如何在 CentOS 中为 docker 守护程序添加变量?

How to add variable to docker daemon in CentOS?

我想在 docker 中创建注册表镜像。我在启动时将 tutorial. So,I want to add this variable "--registry-mirror=http://10.0.0.2:5000" 读给 docker 守护进程。

我已经成功 mac。我将行添加到 /var/lib/boot2docker/profile:

EXTRA_ARGS="--registry-mirror=http://192.168.59.103:5555"

加入mac后即可生效。所以我在 CentOS 中做同样的事情。我在这个 :

中使用命令
sudo sed -i 's|other_args=|other_args=--registry-mirror=http://<my-docker-mirror-host> |g' /etc/sysconfig/docker
sudo sed -i "s|OPTIONS='|OPTIONS='--registry-mirror=http://<my-docker-mirror-host> |g" /etc/sysconfig/docker
sudo service docker restart

它使我的“/etc/sysconfig/docker”在 CentOS 中如下所示,这是我的 docker 文件:

# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d

OPTIONS=--selinux-enabled -H fd:// -g="/opt/apps/docker"

other_args="--registry-mirror=http://10.11.150.76:5555"

然后,我使用以下命令重新启动 docker:

service docker restart

但是,镜像在 CentOS 中不起作用。我使用命令:

ps -ef

它没有将变量添加到 docker 守护程序。怎么了?

/etc/sysconfig/docker 文件中,更改:

OPTIONS=--selinux-enabled -H fd:// -g="/opt/apps/docker"

进入:

OPTIONS=--selinux-enabled -H fd:// -g="/opt/apps/docker" --registry-mirror=http://10.11.150.76:5555

我帮不了你other_args,我不知道这个选项。

如果您使用 yum install docker,您可能会遇到 docker 服务配置文件的问题。

然后你需要检查你的系统服务配置文件,看看它是否使用other_args作为启动docker的参数。默认情况下,服务配置文件应该放在/usr/lib/systemd/system/docker.service,用任何编辑器编辑它,检查ExecStart部分,添加other_args

例如,ExecStart=/usr/bin/docker -d --selinux-enabled $other_args