GPU-enabled SSH server in Docker (CUDA/OpenCL). Minimal, production-friendly setup to expose SSH on host port 2222 and persist user home data via a named volume.
- Docker (Windows: Docker Desktop with WSL2)
- NVIDIA GPU + drivers
- NVIDIA Container Toolkit
- SSH client
- Build and start everything:
.\restart.bat- Stop services:
.\stop.batdocker build -t cuda-ssh .docker-compose up -d- Basic:
docker run --gpus all -d -p 2222:22 cuda-ssh- With host volumes mapped to user homes:
docker run --gpus all -d -p 2222:22 \
-v /path/on/host/user1:/home/user1 \
-v /path/on/host/user2:/home/user2 \
cuda-sshdocker run -d --gpus all -p 2222:22 \
-e NVIDIA_VISIBLE_DEVICES=all \
-e NVIDIA_DRIVER_CAPABILITIES=compute,utility \
cuda-sshssh user1@localhost -p 2222
ssh user2@localhost -p 2222- Enter the container with a sudo-capable account (one from
superusers.txt):
docker exec -it <container_id> bash - Add or update a user and optionally grant sudo:
sudo /root/create_users.sh add alice 'Passw0rd!' --sudo - The script updates
AllowUsersand sends a HUP tosshd, so SSH access for the new user becomes available immediately.
This project uses a named volume for /home, so changes to examples/ copied into the image won't appear in an existing volume automatically.
To solve this, docker-compose.yml bind-mounts local ./examples read-only into the container at /mnt/examples-src, and the container runs /root/sync_examples.sh on startup to mirror them into /home/examples.
Notes:
- Sync is mirror-like (uses
--delete): files removed locally from./examplesare removed from/home/examples. - You can run it manually in a running container:
docker exec -it <container_id_or_name> bash -lc "/root/sync_examples.sh"
docker exec -it <container_id> /bin/bashThe named volume is fixed: cuda-ssh_home-data.
- Create a backup (in the current directory), preserving permissions:
docker run --rm -v cuda-ssh_home-data:/from -v ${PWD}:/backup \
alpine sh -c "cd /from && tar -czf /backup/home-data.tar.gz ."- Restore on another machine:
docker volume create cuda-ssh_home-data
docker run --rm -v cuda-ssh_home-data:/to -v ${PWD}:/backup \
alpine sh -c "cd /to && tar -xzf /backup/home-data.tar.gz"- Inspect the volume mountpoint (optional):
docker volume inspect cuda-ssh_home-data --format "{{.Mountpoint}}"- Windows (Docker Desktop, WSL2) physical paths:
\\wsl$\docker-desktop-data\data\docker\volumes\cuda-ssh_home-data\_data- On some versions:
\\wsl$\docker-desktop-data\version-pack-data\community\docker\volumes\cuda-ssh_home-data\_data