Docker Daemon Config – Opening ports for dockerd

docker

I want to open up TCP to the docker daemon so that Jenkins can build containers against it.

I'm getting lots of info about how to do this. Hoping to get the best method.

Goals of dockerd:

  • Listen over TCP and local unix socket.
  • Persistence through reboots.
  • Host-Specific Authorization for security. Only allow access from specific host. (could be done w/ iptables)

This is an Ubuntu Xenial host.

Current Dockerd Run Info:

root@host:# ps -ef |grep dockerd
root      1171     1  0 17:51 ?        00:00:04 /usr/bin/dockerd -H fd://

Docker config snippet (/etc/init/docker.conf):

post-start script
        DOCKER_OPTS=
        DOCKER_SOCKET=
        if [ -f /etc/default/$UPSTART_JOB ]; then
                . /etc/default/$UPSTART_JOB
        fi

        if ! printf "%s" "$DOCKER_OPTS" | grep -qE -e '-H|--host'; then
                DOCKER_SOCKET=/var/run/docker.sock
        else
                DOCKER_SOCKET=$(printf "%s" "$DOCKER_OPTS" | grep -oP -e '(-H|--host)\W*unix://\K(\S+)' | sed 1q)
        fi

        if [ -n "$DOCKER_SOCKET" ]; then
                while ! [ -e "$DOCKER_SOCKET" ]; do
                        initctl status $UPSTART_JOB | grep -qE "(stop|respawn)/" && exit 1
                        echo "Waiting for $DOCKER_SOCKET"
                        sleep 0.1
                done
                echo "$DOCKER_SOCKET is up"
        fi
end script

How should I go about this?

Best Answer

Found an applicable and clean answer on this blog

Steps:

Edit This file:

sudo vi /lib/systemd/system/docker.service

Look for the existing ExecStart line:

ExecStart=/usr/bin/docker daemon -H fd://

Add your desired config:

ExecStart=/usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:3272

Restart:

systemctl daemon-reload
sudo service docker restart

After that, my daemon was listening on 3272 and was ready to go!