Skip to content

Instantly share code, notes, and snippets.

@dnaprawa
Last active June 10, 2024 17:09
Show Gist options
  • 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...

@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