Set Docker_Opts in centos

2019-03-08 15:33发布

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

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

I can make docker run correctly by typing

sudo /usr/bin/docker -H tcp://0.0.0.0:4243 -d &

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.

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)

I need to be able to start docker with just

service docker start

or it will cause issues in my current deployment playbook.

Any thoughts on what I can do to set DOCKER_OPTS and not have to do it every time I restart docker?

标签: centos docker
12条回答
疯言疯语
2楼-- · 2019-03-08 16:11

It worked for me when I followed how its shown in the posts above with drop-in replacement files in: /etc/systemd/system/docker.service.d

查看更多
姐就是有狂的资本
3楼-- · 2019-03-08 16:11

Based on https://docs.docker.com/engine/admin/configuring/

sudo mkdir /etc/systemd/system/docker.service.d
sudo vi /etc/systemd/system/docker.service.d/docker.conf

[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// -D -H tcp://127.0.0.1:4243

sudo systemctl daemon-reload
sudo systemctl restart docker

查看更多
时光不老,我们不散
4楼-- · 2019-03-08 16:12

I believe things have changed now, this answer by Brian Ogden had worked for me earlier but didn't work on my environment today, probably with the updated versions of the docker, kernel, and OS.

CentOS 7.4.1708 (on AWS)
Docker 17.03.2-ce
API 1.27

This is what worked after few hit and trials. I could not find it documented anywhere.

In file /etc/systemd/system/docker.service.d/execstart.conf, replace the last ExecStart (there are two) with below

ExecStart=/usr/bin/dockerd --graph=/var/lib/docker --storage-driver=overlay -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock

Now, my files looks like this

# cat /etc/systemd/system/docker.service.d/execstart.conf
[Service]
Restart=always
StartLimitInterval=0
RestartSec=15
ExecStartPre=-/sbin/ip link del docker0
ExecStart=
ExecStart=/usr/bin/dockerd --graph=/var/lib/docker --storage-driver=overlay -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
#

Once, the above file is changed just the run the below command to activate the changes.

# systemctl daemon-reload && systemctl stop docker && rm -f /var/run/docker.sock && systemctl start docker

To verify if everything is working fine, you can run any (or all) of below commands

# systemctl status docker.service | grep tcp
           ├─21812 /usr/bin/dockerd --graph=/var/lib/docker --storage-driver=overlay -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
#
# netstat -an | grep 4243
tcp6       0      0 :::4243                 :::*                    LISTEN
#
# ps aux | grep [4]243
root     21812  1.0  0.8 1017512 67876 ?       Ssl  15:11   0:06 /usr/bin/dockerd --graph=/var/lib/docker --storage-driver=overlay -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
#
# docker -H :4243 info
查看更多
走好不送
5楼-- · 2019-03-08 16:18

I am working on centos 7.

I just want to add insecure-registry in docker config file then I changed "DOCKER_OPTS=--insecure-registry=...." in /etc/sysconfig/docker while it did not work.

While I saw a INSECURE_REGISTRY in the config so I changed this variable and it WORKS!

So I guess DOCKER_OPTS does not work here!

But it worked on my unbuntu 14!

It is really frustrating when using docker!

查看更多
时光不老,我们不散
6楼-- · 2019-03-08 16:23

With Docker 1.7.1 on CentOS 7 neither modifying /usr/lib/systemd/system/docker.service or /etc/sysconfig/docker worked for me. It seems that in systemd sets up the socket, so in order to change the group you have to edit SocketGroup in /usr/lib/systemd/system/docker.socket

[Unit]
Description=Docker Socket for the API
PartOf=docker.service

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=jenkins

[Install]
WantedBy=sockets.target
查看更多
做个烂人
7楼-- · 2019-03-08 16:28

I Think on CentOS, you can try setting the options as below in the file /etc/sysconfig/docker

other_args="-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock"

Then restart the docker and try checking if the port is opening using

netstat -plt | grep 4243 

This should list if listening

查看更多
登录 后发表回答