docker: 23 items found.

如何修改microk8s的docker镜像源

适用于 MicroK8s 版本 1.23 或更高版本

MicroK8s 1.23 及更高版本为每个镜像注册表使用单独的 hosts.toml 文件。对于 docker.io,可以在 /var/snap/microk8s/current/args/certs.d/docker.io/hosts.toml 中找到它。

编辑该文件,使其内容看起来像这样:


# /var/snap/microk8s/current/args/certs.d/docker.io/hosts.toml
server = "https://my.registry.internal:5000"

[host."my.registry.internal:5000"]
capabilities = ["pull", "resolve"]

然后,重新启动 MicroK8s:

microk8s stop
microk8s start
More ~

docker 容器安全与firewalld

docker 容器暴露的端口不会因 firewalld 防火墙策略阻断!

最近发现一个问题,docker run 了几个容器,暴雷了 8080, 9090 等等几个端口,一直以为 CentOS 有 firewalld 防火墙在,加了这些端口只允许内网访问,就可以高枕无忧了。
结果有次查看 netstat,居然有一些国外的 IP 连接。这才知道原来有防火墙,容器也不安全!

More ~

How to Check if a File or Directory Exists in Bash

Many times when writing Shell scripts, you may find yourself in a situation where you need to perform an action based on whether a file exists or not.

In Bash, you can use the test command to check whether a file exists and determine the type of the file.

The test command takes one of the following syntax forms:

test EXPRESSION
[ EXPRESSION ]
[[ EXPRESSION ]]
More ~

修改docker镜像

若有个名为nginx的容器:

docker run -it nginx bash

修改内容后退出,使用docker commit命令提交修改。

Usage:  docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

Create a new image from a container's changes

Options:
  -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change list      Apply Dockerfile instruction to the created image
  -m, --message string   Commit message
  -p, --pause            Pause container during commit (default true)

如 :

docker commit -a "John Click" -m "add extra plugins" 2ff7f15ca033 nginx:latest

2ff7f15ca033 为刚才修改的docker容器id。

More ~

podman之docker-compose

podman 3.0开始支持docker-compose,使用docker-compose up
需要先启用podman的api服务 systemctl enable --now podman.socket

20210811152857.png

注意那行Listen,可以执行 export DOCKER_HOST=unix:///run/podman/podman.sock
避免docker-compose运行时报出无法连接的错误:
20210811153045.png

More ~

Dockerfile传参及使用

Dockerfile需要传参时,如Dockerfile中有如下声明

ARG base_img=centos:latest
FROM ${base_img}

ARG arch=x86_64

COPY ${arch}/lib /usr/lib

RUN yum install -y nginx
...

在执行docker build时可以通过参数--build-arg进行传参,如

docker build . -t centos:latest -f Dockerfile --build-arg base_img=centos:7 --build-arg arch=amd64
More ~

wsl 参考的对象类型不支持尝试的操作

wsl无法使用,闪退。起初怀疑是wsl装的有问题,就将wsl按照 https://docs.microsoft.com/zh-cn/windows/wsl/install-win10 重新安装了一次。
安装了docker-desktop后 这个docker-desktop也是闪退。报出Failed to set version to docker-desktop: exit code: -1
这样的错误。

最终百度到:
powershell (管理员)下执行

netsh winsock reset 

不用重启系统。即可。
这时docker-desktop也可以玩了。

More ~

为什么不建议把数据库部署在docker容器内?

前言

近2年Docker非常的火热,各位开发者恨不得把所有的应用、软件都部署在Docker容器中,但是您确定也要把数据库也部署的容器中吗?

这个问题不是子虚乌有,因为在网上能够找到很多各种操作手册和视频教程,小编整理了一些数据库不适合容器化的原因供大家参考,同时也希望大家在使用时能够谨慎一点。

目前为止将数据库容器化是非常不合理的,但是容器化的优点相信各位开发者都尝到了甜头,希望随着技术的发展能够更加完美的解决方案出现。

More ~