Friday, March 09, 2018

Using Docker on a Remote Host: Why so hard?

I have a windows PC at work and an Ubuntu box which happens to be running dockerd.

I have the docker command installed on the windows box, but it occurred to me I should be able to run the command using the Ubuntu box as the host.

Challenge accepted.

After a bit of digging I find :

https://forums.docker.com/t/connect-to-remote-docker-host/13112
>docker -H 192.168.2.1:2357  xxx
should work.

no luck.. fails to connect...

On Ubuntu I run
> netstat | grep docker -i
and find the 2357 port is not open... so back to google.

Turns out you need to tell dockerd to open that socket.
You can do that from the commandline when running dockerd (with the -H flag)
>dockerd -H tpc://:2357

I have no idea where the command line is being run from, so I keep digging.
https://docs.docker.com/engine/admin/systemd/#start-the-docker-daemon

Turns out you can also configure this in a config file... daemon.json
https://docs.docker.com/engine/admin/#configure-the-docker-daemon

I don't need encryption as it's all on my local network.
I add in some hosts...

> sudo systemctl daemon-reload
sudo systemctl restart docker

https://docs.docker.com/engine/reference/commandline/dockerd// "

BIND DOCKER TO ANOTHER HOST/PORT OR A UNIX SOCKET

"

Bang..
https://github.com/moby/moby/issues/22339

Turns out the commandline is also adding hosts... so you can't do both.

I decide to add mine to the command line too and remove it from the json.
> sudo vi  /lib/systemd/system/docker.service

ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 -H tcp://10.10.253.140:2377

the 0.0.0.0 didn't help... 
so I added my actual IP address... 

and that works. This isn't ideal for a few reasons. My IP address being dynamic being one.

This all took a couple of hours I won't get back, so I thought I would share.


No comments:

GitHub Projects