Skip to content

Instantly share code, notes, and snippets.

@dnaprawa
Last active January 2, 2024 11:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save dnaprawa/d3cfd6e444891c84846e099157fd51ef to your computer and use it in GitHub Desktop.
Save dnaprawa/d3cfd6e444891c84846e099157fd51ef to your computer and use it in GitHub Desktop.
Using Docker on remote Docker Host with docker context

Working on remote Docker Host using docker context

SSH keys on Windows

In order to use remote Docker host, as a prerequisite you need SSH enabled (required login using SSH keys).

Generate or find your public SSH key

Go to C:\Users\YOUR_USERNAME\.ssh and copy content of id_rsa.pub file

If the file does not exist, generate the SSH key-pair using following command

ssh-keygen -t rsa -b 4096

Setting up SSH keys to remote machine

Copying your public ssh key to machine

You can use password-based authentication to get into linux machine for the first time, and then use the following command:

echo your_public_ssh_key >> ~/.ssh/authorized_keys

Adding permissions

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Docker Context setup

Set a docker context

with:

docker context create workshop-vm --docker host=ssh://user@host

Switch to context:

docker context use workshop-vm

Issue commands as you normally would...

@danarj
Copy link

danarj commented Sep 4, 2023

I have this error and I can't figure it what wrong


docker ps
error during connect: Get "http://docker.example.com/v1.24/containers/json": command [ssh -o ConnectTimeout=30 -l root -p 2376 -- 192.168.49.136 docker system dial-stdio] has exited with exit status 255, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=banner exchange: Connection to UNKNOWN port -1: Connection refused

@ggutierrez-sunbright
Copy link

most likely, it is just trying for you to confirm the host is part of the known hosts.
if you try running ssh whateveruser@whateveraddress it will prompt for your input. tell ssh you trust the host, and try again with docker ps

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