Skip to content

Instantly share code, notes, and snippets.

@bparaj
Created February 14, 2023 10:11
Show Gist options
  • Save bparaj/2cd5276a17501debca48fe477a4b4c48 to your computer and use it in GitHub Desktop.
Save bparaj/2cd5276a17501debca48fe477a4b4c48 to your computer and use it in GitHub Desktop.
How to share ssh agent with a docker container

You might want to ssh into a docker container and pull some remote repository which requires the SSH keys stored on the host machine. Edit your docker-compose file as follows:

  1. Set the environment variable SSH_AUTH_SOCK to the socket being used by the agent.
  2. Mount that agent in the container.
services:
  app:
    environment:
      - SSH_AUTH_SOCK=/ssh-agent
    volumes:
      - ${SSH_AUTH_SOCK}:/ssh-agent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment