How To Securely Connect To Docker Running On A Remote Host

Quick and easy secure way to connect to remote docker daemon from your local machine.

How To Securely Connect To Docker Running On A Remote Host

One of the main challenges with developing on a Windows machine is docker support. It's just not as good as yet as it is on Linux. If you have access to a remote host that runs docker daemon that you can leverage, or you want to monitor or control docker on a remote host from your local machines, there are few options. And it's not difficult at all!

The first was is documented here. That may be good for lab and non-production environments or if you don't really care much about the security of the machine (maybe it's a temporary VM you just provisioned for a quick job).

However, another quick and secure way is to tunnel over SSH which is RELATIVELY more secure than the previous option and doesn't require any setup on the docker daemon side, especially if you already have an SSH connection to the remote daemon setup.

In WSL, export DOCKER_HOST=ssh://user@host

Then run docker info. If you have an SSH key and passphrase setup on your local machine to connect to that machine, you will be prompted for it and the command will execute on the remote host.

The above will only set up your current shell session to communicate with the remote docker daemon. If you want to make this a persistent setup, export that line to your .bashrc file so that it applies to every session you create from that point on.