How to make docker listening to unix and TCP socket under centos with systemd How to make docker listening to unix and TCP socket under centos with systemd docker docker

How to make docker listening to unix and TCP socket under centos with systemd


So don't touch the docker.socket file or anything. Systemd has a concept of DropIns and you can override parts of the services using a dropin file.

So create the dropin folder for the service first

mkdir -p /etc/systemd/system/docker.service.d/

Then your create a config file

cat > /etc/systemd/system/docker.service.d/90-docker.conf <<EOF[Service]ExecStart=ExecStart=/usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:2375

The first ExecStart= blanks the original command and second ExecStart specifies the new command we want to override

Now we should restart the docker service

systemctl daemon-reloadsystemctl restart docker

Now your service would also be listening at 2375. I believe currently the host option cannot be controlled using /etc/docker/daemon.json. See the below link for more details

https://docs.docker.com/engine/reference/commandline/dockerd/#docker-runtime-execution-options


  1. cd /lib/systemd/system/
  2. vim docker-tcp.socket
  3. paste thie to docker-tcp.socket

    [Unit]Description=Docker Socket for the APIPartOf=docker.service[Socket]ListenStream=2375BindIPv6Only=bothService=docker.service[Install]WantedBy=sockets.target
  4. systemctl daemon-reload

  5. systemctl stop docker.service
  6. systemctl enable docker-tcp.socket
  7. systemctl start docker-tcp.socket
  8. systemctl start docker.service
  9. verify 2375 port is opened docker -H 127.0.0.1 ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES


I actually just posted this answer to an open issue on Github for PhotonOS. I created a gist with the instructions doc markdown as well as the equivalent shell script.

It allows for maintaining both local unix socket as well as remote TCP-based access to the API. Unlike most instructions, it follows the Docker supported method of creating the docker.socket service and binding it to docker service as a dependency, rather than hard-coding either/or TCP or unix fd sock on the command line, or hacking any system files that get overwritten at every upgrade.

Gist is at: https://git.io/fjhhO