Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Docker Container SSH Keys

Traun Leyden edited this page Nov 10, 2015 · 5 revisions

Method 1: Copy your key inside the docker container

In the docker container:

$ mkdir ~/.ssh

From the host:

Find the container id

$ docker ps

Assume it's 9109e0e544b6.

Copy the keys from the host->container:

$ docker cp ~/.ssh/id_rsa 9109e0e544b6:/root/.ssh
$ docker cp ~/.ssh/id_rsa.pub 9109e0e544b6:/root/.ssh

Now, you have to tell your ssh client to use that key with these steps:

$ eval "$(ssh-agent)"
$ ssh-add ~/.ssh/id_rsa_tleyden

Verify SSH key

Verify by finding one of the hostnames and running the following command inside your docker container:

$ cd ansible/playbooks
$ ansible ec2-54-237-94-9.compute-1.amazonaws.com -i inventory -m ping -u centos

(replacing ec2-54.. with actual hostname)

Method 2: Generate a new key inside docker container and authorize key on all AWS instances

Lets say you have a key on your osx workstation called you_id_rsa_osx, and you’ve created a docker container and inside your docker container you’ve created a second key, called you_id_rsa_docker. You started the cluster on your OSX workstation, and used the you_id_rsa_osx as the key in the aws cloudformation settings.

but since you want to also be able to connect to your cluster from inside the docker container, you need to get the you_id_rsa_docker into all of the aws instances. The way you can do that is:

  • Save you_id_rsa_docker somewhere on your osx workstation
  • Update the putkey.yml file to point to the you_id_rsa_docker file
  • ansible-playbook -l $KEYNAME putkey.yml

Clone this wiki locally