A lightweight, secure, and minimal SSH-based Git server running inside a Docker container.
Prepare an authorized_keys file containing your SSH public key to grant access to the container:
cat ~/.ssh/id_rsa.pub > authorized_keys
Start the container by mapping the repository directory and mounting your authorized_keys file:
docker run -d \
--name mini-git-server \
-p 2222:22 \
-v /path/to/repos-data:/data \
-v /path/to/authorized_keys:/home/git/.ssh/authorized_keys \
yoas1/mini-git-server:latest
-p 2222:22: Maps host port 2222 to the container's SSH port 22.-v /path/to/repos-data:/data: Persistent storage directory for bare Git repositories.-v /path/to/authorized_keys:/home/git/.ssh/authorized_keys: Mounts public SSH keys for passwordless authentication.Test your SSH connection to verify key authentication:
ssh -p 2222 git@<SERVER_IP>
Access the container and initialize a new bare repository with main as the default branch:
# Access container shell
docker exec -it mini-git-server bash
# Initialize repository
cd /data
git init --bare -b main <repo-name>.git
On your local machine, clone the repository, create an initial commit, and push your changes:
# Clone the repository using full SSH syntax
git clone ssh://git@<SERVER_IP>:2222/data/<repo-name>.git
cd <repo-name>
# Create initial commit
echo "# Project Title" > README.md
git add README.md
git commit -m "Initial commit"
# Set default branch and push to remote
git branch -M main
git push -u origin main
Content type
Image
Digest
sha256:493e51d3a…
Size
135 MB
Last updated
about 1 month ago
docker pull yoas1/mini-git-server