Created
September 19, 2016 22:03
-
-
Save djmaze/b8aa28bad56d5d28bc29d3f6f2653502 to your computer and use it in GitHub Desktop.
Using an ssh-agent container in conjunction with docker-compose
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This compose file mounts an SSH agent socket from the named volume "ssh" into a Ruby container. | |
# The SSH_AUTH_SOCK variable is set so everything just works. | |
app: | |
image: ruby | |
volumes: | |
- ssh:/ssh | |
environment: | |
SSH_AUTH_SOCK: /ssh/auth/sock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo -E ./start-agent-with-key | |
ssh-agent | |
Identity added: /keys/id_rsa (/keys/id_rsa) | |
$ docker-compose run --rm app bash | |
root@5f914ff271b9:/# ssh-add -l | |
2048 83:29:38:e9:19:2a:94:68:f6:67:21:78:3a:8a:ed:2a /keys/id_rsa (RSA) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script adds your SSH key from ~/.ssh/id_rsa into an ssh-agent container. | |
# | |
set -euo pipefail | |
declare SSH_DIR=$PWD/ssh | |
# Start agent | |
docker start ssh-agent || docker run -d -v ssh:/ssh --name=ssh-agent whilp/ssh-agent | |
# Add key from id_rsa | |
docker run --rm -v ssh:/ssh:ro -v $SSH_DIR:/keys:ro whilp/ssh-agent ssh-add /keys/id_rsa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment