
Docker packages applications with all dependencies into portable containers. Every container runs from an image. Images are built from Dockerfiles and stored in registries. Podman is a daemonless Docker-compatible alternative.
| Item | Syntax | Description |
|---|---|---|
| docker run | docker run [OPTIONS] IMAGE [COMMAND] | Run a container from an image |
| -d | docker run -d nginx | Detached mode — run in background |
| -p | docker run -p 8080:80 nginx | Port mapping host:container |
| -v | docker run -v /host/path:/container/path | Bind mount volume |
| -e | docker run -e ENV_VAR=value | Set environment variable |
| --name | docker run --name myapp nginx | Assign container name |
| --rm | docker run --rm ubuntu echo hello | Auto-remove when container exits |
| -it | docker run -it ubuntu bash | Interactive terminal |
| --network | docker run --network mynet myapp | Connect to network |
| docker ps | docker ps / docker ps -a | List running / all containers |
| docker images | docker images | List local images |
| docker pull | docker pull ubuntu:22.04 | Pull image from registry |
| docker push | docker push myregistry/myimage:tag | Push image to registry |
| docker build | docker build -t myimage:tag . | Build image from Dockerfile in current dir |
| docker exec | docker exec -it mycontainer bash | Execute command in running container |
| docker logs | docker logs -f mycontainer | Stream container logs |
| docker stop | docker stop mycontainer | Gracefully stop container (SIGTERM) |
| docker kill | docker kill mycontainer | Force stop container (SIGKILL) |
| docker rm | docker rm mycontainer | Remove stopped container |
| docker rmi | docker rmi myimage:tag | Remove image |
| docker volume | docker volume create / ls / rm / inspect | Manage named volumes |
| docker network | docker network create / ls / rm | Manage networks |
| docker inspect | docker inspect mycontainer | Detailed JSON info about container |
| docker stats | docker stats | Live resource usage for containers |
| docker cp | docker cp mycontainer:/path/file ./local | Copy files between container and host |
| docker commit | docker commit mycontainer myimage:new | Create image from container (prefer Dockerfile) |
| docker tag | docker tag myimage:latest myimage:v1.0 | Tag image with new name |
| docker login | docker login registry.example.com | Authenticate to registry |
| docker system prune | docker system prune -af | Remove all unused containers, images, networks |
| podman | podman run/build/push/pull/ps | Podman: drop-in Docker replacement, daemonless, rootless |
# Docker essential commands # ── Pull and run ────────────────────────────────────────────── docker pull ubuntu:22.04 docker run --rm ubuntu:22.04 echo "Hello from container" docker run -it ubuntu:22.04 bash # interactive shell # Run web server docker run -d --name nginx-test -p 8080:80 nginx:alpine curl http://localhost:8080 # test it docker logs nginx-test # check logs docker stop nginx-test && docker rm nginx-test # ── Build image ─────────────────────────────────────────────── mkdir myapp && cd myapp cat > Dockerfile << 'EOF' FROM python:3.12-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 8080 USER nobody CMD ["python", "app.py"] EOF docker build -t mywebuniversity/api:1.0 . docker build -t mywebuniversity/api:1.0 --no-cache . # force rebuild docker build --build-arg ENV=production -t myapp . # ── Run your image ───────────────────────────────────────────── docker run -d \ --name mywebuniversity-api \ -p 8080:8080 \ -e DATABASE_URL=postgresql://db:5432/mydb \ -e LOG_LEVEL=info \ --restart unless-stopped \ mywebuniversity/api:1.0 docker exec -it mywebuniversity-api bash # debug inside docker logs -f mywebuniversity-api # stream logs docker stats mywebuniversity-api # resource usage # ── Volumes ──────────────────────────────────────────────────── docker volume create myapp-data docker run -v myapp-data:/app/data myapp # named volume docker run -v $(pwd)/data:/app/data myapp # bind mount docker volume inspect myapp-data docker volume rm myapp-data # ── Registry ────────────────────────────────────────────────── docker tag mywebuniversity/api:1.0 ghcr.io/myorg/api:1.0 docker login ghcr.io -u myuser --password-stdin <<< "$GITHUB_TOKEN" docker push ghcr.io/myorg/api:1.0 docker pull ghcr.io/myorg/api:1.0 # ── Podman (drop-in replacement) ────────────────────────────── # All docker commands work with podman: podman run -d --name nginx -p 8080:80 nginx podman ps; podman logs nginx; podman stop nginx # Rootless containers — no daemon required podman run --rm alpine echo "rootless container!" # Generate systemd unit for auto-start podman generate systemd --name nginx --files --new