Docker – Remote Host Configuration Windows OS

When setting up docker, there are few images one configures/compose to run on-demand triggered by an external system (like Python scripts for particular actions and similar).

To achieve this Kubernetes has come to the rescue (cron-job) and much more, but then if you want to run docker containers on-prem to get these containers triggered via external systems, docker remote host comes to the rescue.

In this post I would like to share few key commands which were handy to be known for any one try to setup docker host remotely and trigger commands on the same, from their local environment.

The key article I would take reference from would be as follows

https://docs.microsoft.com/en-us/virtualization/windowscontainers/management/manage_remotehost

Step 1: Generate Certificates on the (Remote) docker Host

docker run --rm --user ContainerAdministrator -e SERVER_NAME=$(hostname) 
-e IP_ADDRESSES=127.0.0.1,<<Remote Host IP>> -v "c:\programdata\docker:c:\programdata\docker" 
-v "$env:USERPROFILE\.docker:c:\users\<<user name>>\.docker" stefanscherer/dockertls-windows

Note: Ensure this command switch “–user ContainerAdministrator” is in place else you will recevie few folder access issues

https://hub.docker.com/r/stefanscherer/dockertls-windows/

Once the above runs successfully, you will find the following folder in you Docker Host (remote) , with the relevant certificates available for you to copy over to client system

Step 2: Docker Client Configuration

Now once the remote docker host is configured now we move over to out client environment in which we need to download the docker CLI via the following URL (Windows)

https://docs.docker.com/engine/install/binaries/#install-server-and-client-binaries-on-windows

The command for setting up CLI are very simple, just unzip the archive to “C:\Program Files\Docker

Once the binaries are installed on your system and you have added the path to the “PATH” environment variable.

Just then to connect to remote host configure the following

Copy over the cert files to the following location “C:\Users\<<user name>>\.docker” and rename the files which have “server-” key word in them resulting in following

Now configure the following environment variables

DOCKER_CERT_PATHC:\Users\<<user name>>\.docker
DOCKER_HOSTtcp://<<remote host IP>>:2376
DOCKER_TLS_VERIFY1

And thats all done, now if you open you command prompt on your client and run the following commands

docker version
docker info
In the above the “Name” should represent your remote docker host name. (hidden above)

All the resultant output would be driven by the remote docker host, and this allows you to manage remote docker host via client.

Leave a Reply

Your email address will not be published.

*