16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/open-dock/docker.rb', line 16
def self.copy_ssh_credentials_command(container_name)
<<-EOH
ID=$(docker inspect -f '{{.Id}}' #{container_name})
# Container folder
if sudo test -d "/var/lib/docker/aufs"; then
CONTAINERS_DIR=/var/lib/docker/aufs/mnt
SSH_DIR=$CONTAINERS_DIR/$ID/root/.ssh
elif sudo test -d "/var/lib/docker/btrfs"; then
CONTAINERS_DIR=/var/lib/docker/btrfs/subvolumes
SSH_DIR=$CONTAINERS_DIR/$ID/root/.ssh
elif sudo test -d "/var/lib/docker/devicemapper"; then
CONTAINERS_DIR=/var/lib/docker/devicemapper/mnt
SSH_DIR=$CONTAINERS_DIR/$ID/rootfs/root/.ssh
fi
echo SSH container folder: $SSH_DIR
if sudo test ! -d "$SSH_DIR" ; then
sudo mkdir $SSH_DIR
fi
echo Copying authorized_keys and id_rsa.pub files
sudo touch $SSH_DIR/authorized_keys
sudo cat ~/.ssh/authorized_keys | sudo tee -a $SSH_DIR/authorized_keys
sudo cat ~/.ssh/id_rsa.pub | sudo tee -a $SSH_DIR/authorized_keys
sudo chmod 600 $SSH_DIR/authorized_keys
EOH
end
|