Welcome! This repository is designed to help you learn Docker and build containers in a consistent environment using GitHub Codespaces, regardless of whether you're on Windows, macOS, or Linux.
-
Open in Codespaces
- Click the green "Code" button at the top of this repository
- Select "Codespaces" tab
- Click "Create codespace on main"
- Wait for the environment to set up (1-2 minutes)
-
Verify Docker Installation
docker --version docker compose version
-
You're Ready! Docker and Docker Compose are pre-installed and configured.
β οΈ Important: If you get a "permission denied" error when running Docker commands, see the Troubleshooting Guide or rebuild your container: Command Palette β "Codespaces: Rebuild Container"
If you prefer to work locally, you'll need:
- Docker Desktop (Windows/macOS)
- Docker Engine (Linux)
- VS Code with the Dev Containers extension
This repository includes several example projects to get you started:
A basic nginx web server serving a custom HTML page.
cd examples/simple-web
docker build -t simple-web .
docker run -d -p 8080:80 simple-webThen open the forwarded port to see your web page!
A Python web application.
cd examples/python-app
docker build -t python-app .
docker run -d -p 8000:8000 python-appA multi-service application with Flask and Redis.
cd examples/docker-compose-example
docker compose up -dTo stop:
docker compose down# Build an image from a Dockerfile
docker build -t my-image-name .
# Build with a specific Dockerfile
docker build -t my-image -f Dockerfile.dev .# Run a container
docker run my-image-name
# Run in detached mode (background)
docker run -d my-image-name
# Run with port mapping
docker run -p 8080:80 my-image-name
# Run with volume mount
docker run -v $(pwd):/app my-image-name
# Run with environment variables
docker run -e MY_VAR=value my-image-name# List running containers
docker ps
# List all containers (including stopped)
docker ps -a
# Stop a container
docker stop container-id
# Remove a container
docker rm container-id
# View container logs
docker logs container-id
# Execute command in running container
docker exec -it container-id bash# List images
docker images
# Remove an image
docker rmi image-id
# Pull an image from Docker Hub
docker pull nginx:latest
# Tag an image
docker tag my-image:latest my-image:v1.0# Start services
docker compose up
# Start in background
docker compose up -d
# Stop services
docker compose down
# View logs
docker compose logs
# Rebuild services
docker compose up --build# Remove all stopped containers
docker container prune
# Remove all unused images
docker image prune
# Remove all unused volumes
docker volume prune
# Remove everything unused
docker system prune -aHere's a template to get you started:
# Choose a base image
FROM ubuntu:latest
# Set working directory
WORKDIR /app
# Copy files
COPY . .
# Install dependencies
RUN apt-get update && apt-get install -y \
package-name \
&& rm -rf /var/lib/apt/lists/*
# Expose port (documentation only)
EXPOSE 8080
# Set environment variables
ENV MY_VAR=value
# Run command when container starts
CMD ["executable", "param1", "param2"]- Start with Simple Web - Learn basic Docker commands and image building
- Try Python App - Understand multi-step builds and dependencies
- Explore Docker Compose - Learn to orchestrate multiple containers
- Create Your Own - Build something custom!
If you get a "port already in use" error:
# Find what's using the port
docker ps
# Stop the container using that port
docker stop container-idCheck the logs:
docker logs container-idClean up unused resources:
docker system prune -aIn Codespaces, Docker should work automatically. If you have issues:
# Check Docker is running
docker ps
# Restart the codespace if needed- Docker Documentation
- Docker Hub - Find pre-built images
- Dockerfile Best Practices
- Docker Compose Documentation
Feel free to add your own examples! Create a new folder under examples/ with:
- A
Dockerfile - A
README.mdexplaining what it does - Any necessary application files
- Always use
.dockerignore- Similar to.gitignore, exclude unnecessary files - Keep images small - Use alpine or slim base images when possible
- One process per container - Follow the single responsibility principle
- Use multi-stage builds - For smaller production images
- Don't run as root - Create a user in your Dockerfile for security
- Tag your images - Use meaningful version tags, not just
latest
Remember: The beauty of Codespaces is that everyone gets the exact same environment. No more "it works on my machine" problems!
Questions? Open an issue or reach out to the repository maintainer.