Monday, December 25, 2017

docker enabling remote daemon administration

one can use the -H option

https://docs.docker.com/engine/reference/commandline/dockerd/#examples
https://docs.docker.com/engine/admin/systemd/#start-automatically-at-system-boot
https://docs.docker.com/engine/reference/commandline/dockerd//#daemon-configuration-file

don't try to use /etc/docker/daemon.json , it's not supported for this option

Do this:

sudo less /usr/lib/systemd/system/docker.service

change
ExecStart=/usr/bin/dockerd
into
ExecStart=/usr/bin/dockerd -D -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
(if this fails, remove the -D)

sudo systemctl daemon-reload
sudo systemctl restart docker

sudo systemctl stop firewalld

sudo less /var/log/messages

sudo journalctl -xe

netstat -an | grep 2375


Now you can connect remotely (in this case I am using localhost, but you can use an IP or a hostname if remotely connecting):

docker -H localhost:2375 info


I have tried with
export DOCKER_HOST="tcp://0.0.0.0:2375"
systemctl daemon-reload
systemctl restart docker


but it didn't work for me...


This allows to do cool stuff like:

curl http://localhost:2375/images/json | python -mjson.tool



One can use also the HTTP REST Api https://docs.docker.com/develop/sdk/examples/

No comments: