Docker packages an app and everything it needs into a container that runs the same on any machine. This cheat sheet covers the commands for images, containers, Compose, and cleanup.
Images
| Command | What it does |
|---|---|
docker pull <image> |
Download an image from a registry |
docker build -t name . |
Build an image from a Dockerfile |
docker images |
List local images |
docker rmi <image> |
Remove an image |
docker tag <img> <new> |
Add another tag to an image |
docker history <image> |
Show the layers of an image |
Containers
| Command | What it does |
|---|---|
docker run <image> |
Create and start a container |
docker run -d -p 8080:80 <image> |
Run detached, mapping host port to container port |
docker ps |
List running containers (ps -a for all) |
docker stop <id> / start <id> |
Stop or start a container |
docker rm <id> |
Remove a stopped container |
docker exec -it <id> bash |
Open a shell inside a running container |
docker logs -f <id> |
Follow the logs of a container |
Docker Compose
| Command | What it does |
|---|---|
docker compose up -d |
Start the services in docker-compose.yml |
docker compose down |
Stop and remove the services |
docker compose build |
Build or rebuild the services |
docker compose ps |
List the running compose services |
docker compose logs -f |
Follow the logs for all services |
System, volumes, network
| Command | What it does |
|---|---|
docker system prune |
Remove unused data to free space |
docker volume ls |
List volumes |
docker network ls |
List networks |
docker cp <id>:/path ./ |
Copy files out of a container |
docker inspect <id> |
Show full details as JSON |
docker stats |
Live view of resource usage |
Frequently Asked Questions
What is Docker?
Docker is a platform that packages an application and its dependencies into a container, so it runs the same way on any machine that has Docker.
What is the difference between an image and a container?
An image is the read-only template. A container is a running instance created from an image, like a process started from a program.
What is the difference between docker run and docker start?
run creates a new container from an image and starts it. start restarts an existing container that was stopped earlier.
How do I free up disk space used by Docker?
Run docker system prune to remove stopped containers, unused networks, and dangling images. Add the volumes flag to also clear unused volumes.
Browse our free developer tools for JSON, YAML, and more.