📝 Code Tips & Developer Notes

Enable Docker SSH-Agent #

Published:

Use ssh-agent to let Docker builds access private repositories securely. Keys should not be copied into images — instead mount the agent socket.

Setup (inside docker container)


nano ~/.bashrc
pkill ssh-agent
eval $(ssh-agent) > /dev/null
ssh-add ~/.ssh/id_rsa
        

Mount or Copy Keys

You have two options:

  • Mount the SSH agent socket (recommended): Docker uses your running agent, no keys inside the container.
  • Copy keys manually (less secure): place id_rsa inside the container, but remove it afterwards.

Usage


docker build --ssh default -t myapp .
        

Now private Git dependencies are available during build.

« 1 2 »