2

On ubuntu i can go into /etc/init/docker.conf and put in DOCKER_OPTS='-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock' to get the json data to display on my browser but how can i do it for Centos?

I have tried creating a file in /etc/sysconfig/docker and placing other_args="-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock" inside the file and restarting docker but it doesn't do anything.

user3412172
  • 489
  • 2
  • 6
  • 10
  • From where did you install the docker package? The one in CentOS (docker-1.10.3-46.el7.centos.14.x86_64) reads `/etc/sysconfig/docker`. The one from Docker corp. (docker-engine-1.12.0-1.el7.centos.x86_64) does not. – larsks Oct 25 '16 at 15:22
  • @larsks i installed it from docker corp (1.12.2) is there any way i can expose the port on centos with docker 1.12.2? I need 1.12+ due to its swarm mode – user3412172 Oct 25 '16 at 15:39

3 Answers3

13

The systemd unit installed by the Docker corp package hardcodes the command line used to start the docker daemon:

[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
[...]

There is no support for reading a file from /etc/sysconfig or elsewhere to modify the command line. Fortunately, systemd gives us the tools we need to change this behavior.

The simplest solution is probably to create the file /etc/systemd/system/docker.service.d/docker-external.conf (the exact filename doesn't matter; it just needs to end with .conf) with the following contents:

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock

And then:

systemctl daemon-reload
systemctl restart docker

This is actually documented on the Docker website in this document, which includes instructions for a more flexible solution that will allow you to use files in /etc/sysconfig to control the daemon.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • On AWS CentOS 7 AMI, somehow restart did not work for me. This worked `systemctl daemon-reload && systemctl stop docker && rm -rf /var/run/docker.sock && systemctl start docker` For some weird reason, `docker.sock` was being created as a directory instead of a socket file. – vikas027 Aug 10 '17 at 04:14
  • There is no need to create an extra file for the same on CentOS 7. I have given my answer in another similar [question](https://stackoverflow.com/a/51116208/3438276). – vikas027 Jul 01 '18 at 14:56
  • Your answer seems to rely on a drop-in file (`/etc/systemd/system/docker.service.d/execstart.conf`) just like this one. – larsks Jul 01 '18 at 16:46
  • Yeah, kind of. I have just tweaked a current file, rather than creating a new one. – vikas027 Jul 01 '18 at 23:36
0

Yes, you can do the configuration thing. But how about a docker solution to a docker problem?

docker run -d \
--name sherpa \                 
-v /var/run/docker.sock:/tmp/docker.sock \
-p 2375:4550 \
djenriquez/sherpa --allow

Proxies access to the socket through port 2375 on localhost.

kwerle
  • 2,225
  • 22
  • 25
-2

1、edit /usr/lib/systemd/system/docker.service to add two params in the service section:

# vim /usr/lib/systemd/system/docker.service

[Service]

ExecStart=

ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

2、reload the configuration, and then restart docker。

# systemctl daemon-reload
# systemctl restart docker

3、to check for success, see if the return the following response。

# ps -ef|grep docker

root 26208 1 0 23:51 ? 00:00:00 /usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

reference from Expose the Docker Remote API on Centos 7?

faryang
  • 55
  • 6
  • 1
    Don't edit `/usr/lib/systemd/system/docker.service`, because it will get replaced next time you install the `docker` package. This is what `/etc/systemd/system` is for. – larsks Jul 01 '18 at 16:41