docker-ssh-clone
Clone a GitHub repo (via SSH) into a Docker container using the host's SSH key.
SKILL.mddocker-ssh-clone/SKILL.md
GitHubDocker Container SSH Git Clone
Clone a GitHub repo (via SSH) into a Docker container using the host's SSH key.
Steps
Create container (if not exists):
docker run -d --name <name> -v ~/MountDir:/data --restart unless-stopped ubuntu:24.04 sleep 86400Install git and openssh inside the container:
docker exec <name> apt-get update && docker exec <name> apt-get install -y git openssh-clientCopy SSH key from host to container:
docker exec <name> mkdir -p /root/.ssh docker cp ~/.ssh/id_ed25519 <name>:/root/.ssh/id_ed25519 docker cp ~/.ssh/id_ed25519.pub <name>:/root/.ssh/id_ed25519.pubSet permissions and SSH config, then clone:
docker exec <name> sh -c " chmod 700 /root/.ssh && chmod 600 /root/.ssh/id_ed25519 && chmod 644 /root/.ssh/id_ed25519.pub && echo 'Host github.com HostName github.com User git IdentityFile /root/.ssh/id_ed25519 StrictHostKeyChecking no' > /root/.ssh/config && git clone git@github.com:<owner>/<repo>.git /data/<repo> "
Pitfalls
- HTTPS with token fails inside container —
docker exechas no interactive credential helper. Use SSH instead. - SSH key permissions must be correct (700 for
.ssh, 600 for private key, 644 for public key). StrictHostKeyChecking nois needed to avoid interactive prompt on first connect.docker cpfails if target directory doesn't exist — create it first withdocker exec.- If the container already has
/root/.ssh, skip themkdirstep.