Correct way to start docker daemon listening to specific port Correct way to start docker daemon listening to specific port docker docker

Correct way to start docker daemon listening to specific port


On Ubuntu (16.04 LTS) with docker-ce (17.03.1~ce-0~ubuntu-xenial) do the following to make docker listen to a TCP port instead of sockets.

Add a file /etc/systemd/system/docker.service.d/override.conf with the following content:

[Service]ExecStart=ExecStart=/usr/bin/dockerd

Add a file /etc/docker/daemon.json with the following content

{    "hosts": [        "tcp://127.0.0.1:2375"    ] }

Reload (systemctl daemon-reload) and restart (systemctl restart docker.service) docker.

For reference: https://github.com/moby/moby/issues/25471

EDIT:

Be careful, so the demon will only listen to that network port ignoring local requests.To make docker listen to both remote and local, edit daemon.json but keep the standard unix socket

{        "hosts" : [                "unix:///var/run/docker.sock",                "tcp://<docker-host-ip-or-localhost>:2375"        ]}

Docker daemon connection options docs


On Mac OSX you'd run the Docker Quickstart Terminal App to see:

Machine default already exists in VirtualBox.Starting machine default...Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.Setting environment variables for machine default...

...

                        ##         .                  ## ## ##        ==               ## ## ## ## ##    ===           /"""""""""""""""""\___/ ===      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~           \______ o           __/             \    \         __/              \____\_______/docker is configured to use the default machine with IP 192.168.99.100For help getting started, check out the docs at https://docs.docker.com

now

docker ps

should work

On Linux e.g. Ubuntu prepending sudo might be necessary. E.g.

docker ps

will lead to:

Get http:///var/run/docker.sock/v1.20/containers/json: dial unix /var/run/docker.sock: permission denied.* Are you trying to connect to a TLS-enabled daemon without TLS?* Is your docker daemon up and running?

but

sudo docker ps

will work.

See https://docs.docker.com/articles/basics/

To check if your docker service is running you can call

 sudo service --status-all 2>&1 | grep docker

and it should show:

[ - ]  docker

Sometimes your docker instllation might be corrupt see: Docker daemon does not start or restart


I found a solution to my problem. I specified docker running on IP x and Port y, but docker then only listens to that socket. I had to add another -H flag with the unix socket in order to listen to local requests:

sudo /usr/bin/docker daemon -H tcp://0.0.0.0:5555 -H unix:///var/run/docker.sock