Docker Commands Cheatsheet — Complete Reference 2026

Essential Docker commands: run, build, push, pull, exec, logs, volumes, networks. Copy-paste examples.

Container Lifecycle

CommandDescription
docker run -d --name myapp nginxRun container in background
docker run -p 8080:80 nginxMap port 8080 to container port 80
docker run -v /host:/container nginxMount volume
docker run --rm alpine echo hiRun and auto-remove
docker start/stop/restart <name>Manage container state
docker rm <name>Remove stopped container
docker rm -f <name>Force remove running container

Images

CommandDescription
docker build -t myapp .Build image from Dockerfile
docker pull nginx:latestDownload image
docker push myuser/myappPush to Docker Hub
docker imagesList local images
docker rmi <image>Remove image
docker image pruneRemove dangling images

Debugging

# Execute command in running container
docker exec -it myapp bash

# View logs
docker logs myapp
docker logs -f myapp          # Follow logs
docker logs --tail 100 myapp  # Last 100 lines

# Inspect container
docker inspect myapp

# Container resource usage
docker stats

Cleanup

# Remove all stopped containers
docker container prune

# Remove unused images, containers, networks
docker system prune

# Nuclear option: remove EVERYTHING
docker system prune -a --volumes

Need These Tools as an API?

TextForge API offers 20+ developer toolkit endpoints. Free tier: 50 requests/day.

Try TextForge API Free →

Related Tools