Skip to content

Instantly share code, notes, and snippets.

@g023
Last active February 9, 2026 21:38
Show Gist options
  • Select an option

  • Save g023/cc7446e546c8070eaa97a3c78140cd01 to your computer and use it in GitHub Desktop.

Select an option

Save g023/cc7446e546c8070eaa97a3c78140cd01 to your computer and use it in GitHub Desktop.
my_simple_docker
#!/bin/bash
# Stop and remove the SSH-enabled CUDA container and optionally the image
# Variables
CONTAINER_NAME="cuda-ssh"
IMAGE_NAME="cuda-ssh"
TAG="12.4"
# Stop the container if running
if podman ps -a --format "{{.Names}}" | grep -q "^$CONTAINER_NAME\$"; then
echo "Stopping container '$CONTAINER_NAME'..."
podman stop $CONTAINER_NAME
else
echo "Container '$CONTAINER_NAME' is not running."
fi
# Remove the container
if podman ps -a --format "{{.Names}}" | grep -q "^$CONTAINER_NAME\$"; then
echo "Removing container '$CONTAINER_NAME'..."
podman rm $CONTAINER_NAME
else
echo "No container to remove."
fi
# Ask if user wants to remove the image
read -p "Do you want to remove the image '$IMAGE_NAME:$TAG'? [y/N]: " remove_image
if [[ "$remove_image" =~ ^[Yy]$ ]]; then
if podman images --format "{{.Repository}}:{{.Tag}}" | grep -q "^$IMAGE_NAME:$TAG\$"; then
echo "Removing image '$IMAGE_NAME:$TAG'..."
podman rmi $IMAGE_NAME:$TAG
else
echo "Image '$IMAGE_NAME:$TAG' not found."
fi
fi
ssh-keygen -f '/$HOME/.ssh/known_hosts' -R '[localhost]:2222'
echo "✅ Done."
#!/bin/bash
# Run the SSH-enabled CUDA container
# Variables
IMAGE_NAME="cuda-ssh"
TAG="12.4"
CONTAINER_NAME="cuda-ssh"
SSH_PORT=2222
WORKSPACE_DIR="$HOME/opencode-work"
CONFIG_DIR="$HOME/.opencode"
CACHE_DIR="$HOME/.cache/opencode"
# Run the container
podman run -d \
--name $CONTAINER_NAME \
--device nvidia.com/gpu=all \
-e NVIDIA_VISIBLE_DEVICES=all \
-e NVIDIA_DRIVER_CAPABILITIES=all \
-p $SSH_PORT:22 \
-v $WORKSPACE_DIR:/workspace \
-v $CONFIG_DIR:/home/dev/.config/opencode \
-v $CACHE_DIR:/home/dev/.cache/opencode \
-w /workspace \
${IMAGE_NAME}:${TAG}
echo "✅ Container '$CONTAINER_NAME' is running."
echo "Connect from VSCode using: ssh dev@localhost -p $SSH_PORT"
#!/bin/bash
# Build an SSH-enabled CUDA container where dev is root (UID 0) and can login with password
# Includes installation of PyTorch and torchvision with CUDA 12.4 support
IMAGE_NAME="cuda-ssh"
TAG="1.1"
USERNAME="dev"
PASSWORD="dev"
# Create temporary Dockerfile
DOCKERFILE=$(mktemp)
cat > "$DOCKERFILE" <<EOF
FROM nvcr.io/nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
# Install SSH server and utilities
# apt install -y libopencv-dev && \ # MIGHT HAVE A PROMPT THAT MESSES THINGS UP
ENV DEBIAN_FRONTEND=noninteractive
RUN apt -y update && \
apt -y upgrade
RUN apt-get install -y openssh-server sudo vim git curl python3-pip nano && \
apt install -y libsuitesparse-dev libeigen3-dev libflann-dev libfreeimage-dev libmetis-dev libgoogle-glog-dev libgflags-dev libgtest-dev libsqlite3-dev libglew-dev libatlas-base-dev libboost-all-dev && \
apt install -y cmake && \
apt install -y libopenimageio-dev && \
apt install -y libopenexr-dev && \
apt install -y openimageio-tools && \
apt install -y libceres-dev && \
apt install -y libcgal-dev && \
apt install -y nvidia-cuda-toolkit && \
mkdir /var/run/sshd && \
apt install cmake && \
apt install nvidia-cuda-toolkit && \
apt install git && \
apt install unzip
RUN apt install -y g++-10 gcc-10 && \
# handle the tzone holding up the build process
RUN ln -fs /usr/share/zoneinfo/UTC /etc/localtime && \
apt-get install -y --no-install-recommends libopencv-dev && \
rm -rf /var/lib/apt/lists/*
## install nerfstudio
# RUN git clone https://github.com/nerfstudio-project/nerfstudio.git && \
# cd nerfstudio && \
# pip install --upgrade pip setuptools && \
# pip install -e .
# Create dev user with UID 0 (effectively root)
RUN useradd -m -u 0 -o -s /bin/bash $USERNAME && \
echo "$USERNAME:$PASSWORD" | chpasswd
# Allow password authentication for root and UID 0 users
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
echo "Match User $USERNAME" >> /etc/ssh/sshd_config && \
echo " PermitRootLogin yes" >> /etc/ssh/sshd_config
# Upgrade pip and install PyTorch with CUDA 12.4 support (use python3 -m pip for clarity)
RUN python3 -m pip install --upgrade pip && \
python3 -m pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124 && \
python3 -c "import torch; print('PyTorch installed:', torch.__version__, 'CUDA available:', torch.cuda.is_available())"
# Expose SSH port
EXPOSE 22
# Start SSH server
CMD ["/usr/sbin/sshd", "-D"]
EOF
# Build the image with verbose output
podman build --progress=plain -t ${IMAGE_NAME}:${TAG} -f "$DOCKERFILE"
rm "$DOCKERFILE"
echo "✅ SSH-enabled CUDA image built: ${IMAGE_NAME}:${TAG}"
echo "Login as '$USERNAME' with full root privileges using password '$PASSWORD'."
echo "PyTorch and torchvision installed with CUDA 12.4 support."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment