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?
Docker is using your local SSH agent. Any keys loaded into your agent will be accessible for the connection: 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
By using Docker secrets we can have a generic image that uses local SSH keys. A secret is a blob of data, such as a password, SSH private key, SSL certificate, or another piece of data that should not be transmitted over a network or stored unencrypted in a Dockerfile or in your application’s source code.
The drawback here is additional complexity due to the machinery required to create and manage a keystore such as Vault by HashiCorp. For SSH key use in a stand-alone Docker container see the methods linked above and consider the drawbacks of each depending on your specific needs.
Basic knowledge of docker compose is a must here. Since you will be accessing the server via SSH keys, you need to add the public SSH key of your local system to your host Linux server's directory where docker-compose file is located and keep the name "id_rsa.pub" just to be sure. I suggest using the linuxserver/openssh-server image.
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:
<username-home>/.ssh/authorized_keys
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With