Docker context how to use specific ssh key

Viewed 7795

I would like to use a docker context to contact a server via ssh. I have a number of different ssh keys on my local. How do I tell a context to use a specific key? I've tried:

docker context create test --docker "host=ssh://<username>@<ip-of-server>,key=C:/path/to/key"

but no dice, it always asks for a password. Is there a way to tell a docker context what ssh key to use?

1 Answers

The key you are trying to use in the example you provided refers to the TLS key.

Docker is using your local SSH agent. Any keys loaded into your agent will be accessible for the connection:

  • if not present already, install a SSH agent;
  • generate the SSH key pair;
  • add the private key to the SSH agent on the machine from which you want to issue the docker commands;
  • add the public key on the target Docker host machine, in the <username-home>/.ssh/authorized_keys
  • now try a regular SSH into the target Docker host(ssh <username>@<ip-of-server>). Accept the fingerprint. If you are not asked for a password, docker won't ask for it either.

Create and activate the docker context, then run a dummy docker command:

docker context create test --docker "host=ssh://<username>@<ip-of-server>"
docker context use test
docker ps
Related