Jan 08, 2018

Bind dockerd to a TCP port

On a modern system (one running Systemd) when installing Docker, the dockerd daemon is run using Systemd' socket activation. By default the socket is /var/run/docker.sock. If you want to connect to a remote machine over TCP, the obvious thing to do is to create /etc/docker/daemon.json and set the hosts list there. But that will conflict with the command line flags for socket activation. The correct way is to override Systemd' socket activation config. Here's how (all command are as root):

mkdir -p /etc/systemd/system/docker.socket.d
echo '[Socket]' > /etc/systemd/system/docker.socket.d/tcp.conf
echo 'ListenStream=2375' >> /etc/systemd/system/docker.socket.d/tcp.conf
systemctl daemon-reload
systemctl restart docker