在 centos 中设置 Docker_Opts [英] Set Docker_Opts in centos
问题描述
我需要在运行 amazon linux (centos) 的主机上设置 docker 以监听 tcp://0.0.0.0/4243.我看到的所有文档都告诉我运行以下命令
I need to set docker to listen to tcp://0.0.0.0/4243 on my host machine running amazon linux (centos). All the documentation I have seen has told me to run the following command
echo DOCKER_OPTS="-H=tcp://127.0.0.1:4243" >> /etc/default/docker
这会将正确的 docker_opts 写入/etc/default/docker.我已经这样做了,但是当我重新启动 docker 时它不听 127.0.0.1
Which will write the correct docker_opts to /etc/default/docker. I've done this, but when I restart docker it does not listen to 127.0.0.1
我可以通过输入使 docker 正确运行
I can make docker run correctly by typing
sudo /usr/bin/docker -H tcp://0.0.0.0:4243 -d &
这可行,但我希望默认选项在 tcp://0.0.0.0:4243 上进行侦听,而不必每次都指定它.
That works, but I want the default option to be listening on tcp://0.0.0.0:4243 without having to specify it every time.
似乎 docker 完全忽略了我的/etc/default/docker 文件,所以设置被忽略了.我还尝试将文件写入/etc/default/docker.io 和/etc/default/docker-io (没想到会发生很多事情)
It seems that docker is completely ignoring my /etc/default/docker file so the settings are being ignored. I also tried writing the file to /etc/default/docker.io and /etc/default/docker-io (didn't really expect much to happen)
我需要能够启动 docker
I need to be able to start docker with just
service docker start
否则会导致我当前的部署手册出现问题.
or it will cause issues in my current deployment playbook.
关于我可以做些什么来设置 DOCKER_OPTS 而不必每次重新启动 docker 时都这样做有什么想法吗?
Any thoughts on what I can do to set DOCKER_OPTS and not have to do it every time I restart docker?
推荐答案
在 RHEL7 中,不用修改 docker.service 单元文件,也可以只编辑/etc/sysconfig/docker 文件:
In RHEL7, instead of modifying your docker.service unit file, you can also just edit your /etc/sysconfig/docker file:
# /etc/sysconfig/docker
# Modify these options if you want to change the way the docker daemon runs
OPTIONS=--selinux-enabled -H unix:///var/run/docker.sock -H tcp://0.0.0.0:4243
然后重启你的 docker 服务.
and then restart your docker service.
对我来说,这比修改服务脚本更可靠.
To me, this is more reliable than modifying the service script.
这篇关于在 centos 中设置 Docker_Opts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!