Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Connect to another host with your docker client, without modifying your local Docker installation

Run commands on remote Docker host

This is how to connect to another host with your docker client, without modifying your local Docker installation or when you don't have a local Docker installation.

Enable Docker Remote API

First be sure to enable the Docker Remote API on the remote host.

This can easily be done with a container.
For HTTP connection use jarkt/docker-remote-api.
For HTTPS connection use whiledo/docker-remote-api-tls.

You can also configure the Docker engine to expose the remote API. Read Enable Docker Remote API with TLS client verification for more information.

Download docker client

If you don't have a local Docker installation, you need to download the docker client, which is a simple executable.
You find the docker client for Linux, MacOS and Windows on download.docker.com.
Take a file of the static directory, e.g. linux/static/stable/x86_64/docker-17.12.0-ce.tgz, and unzip it. You only need the docker or docker.exe file.

As linux user you can also use this tiny script to download it.

Set alias (for Linux)

For HTTP connection set the following alias:
alias dockerx="docker -H=your-remote-server.org:2375"

For HTTPS connection set the following alias:
alias dockerx="docker --tlsverify -H=your-remote-server.org:2376 --tlscacert=/home/me/docker-tls/ca.pem --tlscert=/home/me/docker-tls/cert.pem --tlskey=/home/me/docker-tls/key.pem"

Create .bat file (for Windows)

Create a file "dockerx.bat".
For HTTP connection the content of the bat file should be:
docker -H=your-remote-server.org:2375 %*

For HTTPS connection the content of the bat file should be:
docker --tlsverify -H=your-remote-server.org:2376 --tlscacert=C:\users\me\docker-tls\ca.pem --tlscert=C:\users\me\docker-tls\cert.pem --tlskey=C:\users\me\docker-tls\key.pem %*

HTTPS connection configuration

Docker's Remote API client authentication works with certificates. See Protect the Docker daemon socket or my Enable Docker Remote API with TLS client verification on how to create server and client certificates.
Copy ca.pem (CA certificate), cert.pem (client certificate) and key.pem (client's private key) in /home/me/docker-tls/ or C:\users\me\docker-tls\.

Run commands

Now you can run commands on the remote machine with dockerx (Linux) or dockerx.bat or just dockerx (Windows) instead of docker.
Examples:
dockerx ps
dockerx.bat ps

@BartRobeyns

This comment has been minimized.

Show comment Hide comment
@BartRobeyns

BartRobeyns Feb 18, 2018

The Install Docker from binaries link no longer provides info for installing the Windows Docker Client by itself. Instead, you can go to https://download.docker.com/win/static/stable/x86_64/, and grab the latest zip-file that contains the Docker Client, docker.exe.

The Install Docker from binaries link no longer provides info for installing the Windows Docker Client by itself. Instead, you can go to https://download.docker.com/win/static/stable/x86_64/, and grab the latest zip-file that contains the Docker Client, docker.exe.

@kekru

This comment has been minimized.

Show comment Hide comment
@kekru

kekru Feb 22, 2018

Thanks @BartRobeyns, I updated the text

Owner

kekru commented Feb 22, 2018

Thanks @BartRobeyns, I updated the text

@solvingj

This comment has been minimized.

Show comment Hide comment
@solvingj

solvingj Mar 9, 2018

This is what happens when i run docker.bat ps:

U:\>docker.bat ps
U:\>docker -H=TEMP-HYPERV:2375 ps
U:\>docker -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 ps
U:\>docker -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 ps
U:\>docker -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 ps

and it goes on to infinity until i cancel.

Basically, it happens if you name the script docker.bat specifically, AND run it in the folder where it exists. Name it something else, or run it from another directory.

solvingj commented Mar 9, 2018

This is what happens when i run docker.bat ps:

U:\>docker.bat ps
U:\>docker -H=TEMP-HYPERV:2375 ps
U:\>docker -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 ps
U:\>docker -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 ps
U:\>docker -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 -H=TEMP-HYPERV:2375 ps

and it goes on to infinity until i cancel.

Basically, it happens if you name the script docker.bat specifically, AND run it in the folder where it exists. Name it something else, or run it from another directory.

@kekru

This comment has been minimized.

Show comment Hide comment
@kekru

kekru Mar 19, 2018

Haha thats crazy. Thanks @solvingj, I updated the text to use dockerx.bat instead

Owner

kekru commented Mar 19, 2018

Haha thats crazy. Thanks @solvingj, I updated the text to use dockerx.bat instead

@wxgeorge

This comment has been minimized.

Show comment Hide comment
@wxgeorge

wxgeorge Mar 27, 2018

You also could set DOCKER_HOST in your session ...

You also could set DOCKER_HOST in your session ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment