Docker: Connecting to a Remote Host

I for one, maybe not everyone, but I for a long time though that to be able to communicate with a docker instance I had to be on that box.

First, after digging around I found the DOCKER_HOST environment variable, which served it purpose, and allowed me to connect to one or more of my docker hosts;

$ export DOCKER_HOST="ssh://me@dockerhost
$ docker ps
CONTAINER ID IMAGE...
1b2e8e4a546a casperghst42/pms-docker...
4de622e79fa6 casperghst42/httpserver...
...

Now after (unsuccessly) having looked at VS Code and it's Docker extension (which as of writing is broken in more than one way), I discovered Docker Contexts.

Instead of using DOCKER_HOST one should use docker contexts, which allow to setup multiple hosts to connect to.

Example:

$ docker context ls
NAME         TYPE         DESCRIPTION
default      moby         Current DOCKER_HOST based
dockerhost * moby
....
Setting up a new context is quite easy:
$ docker context create <contextname> --docker "host=ssh://<user>@<host>"
To switch between Docker contexts is also quite easy:
$ docker context use <contextname>
 
Docker is not always easy, until you run into the right explanation. 

Comments

Popular posts from this blog

Apple IOS cannot download song

Kviknet and IPv6

Apple AirPort Express and Digital Jitter..