Skip to content

Instantly share code, notes, and snippets.

@ruliana
Created February 11, 2025 13:34
Show Gist options
  • Save ruliana/59a3d635fb857303326065b7ac0c9b02 to your computer and use it in GitHub Desktop.
Save ruliana/59a3d635fb857303326065b7ac0c9b02 to your computer and use it in GitHub Desktop.
Script to run an interactive shell from Stanford's XCS236 Docker image using Docker
#!/bin/bash
# Check if the container image already exists
if docker image inspect xcs236-env >/dev/null 2>&1; then
echo "Container image already exists. Skipping build."
else
# Build the container
echo "Building container..."
docker build -t xcs236-env .
fi
# Check if the container already exists
if docker ps -a --format '{{.Names}}' | grep -q '^xcs236-container$'; then
echo "Removing existing container..."
docker rm xcs236-container
fi
# Run the container with src directory mounted and remove it when exiting
echo "Running container..."
docker run -it --rm \
-v "$(pwd):/workspace" \
--name xcs236-container \
xcs236-env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment