Docker Cheat Sheet
Basics commmands for docker.
Docker Cheat Sheet
Container Management
Command | Description |
---|---|
docker ps |
List running containers |
docker ps -a |
List all containers |
docker run [OPTIONS] <image> |
Create a container from an image |
docker start <container> |
Start a stopped container |
docker stop <container> |
Stop a running container |
docker restart <container> |
Restart a container |
docker rm [OPTIONS] <container> |
Remove a stopped container |
docker rm -f <container> |
Force remove a running container |
Common Options for docker run
| Option | Description |
|——–|————-|
| -d
| Run container in background and print container ID |
| -p <host_port>:<container_port>
| Publish a container’s port to the host |
| --name <name>
| Assign a name to the container |
| -v <host_path>:<container_path>
| Bind mount a volume |
| --env <key>=<value>
| Set environment variables |
| --network <network>
| Connect a container to a network |
Image Management
Command | Description |
---|---|
docker images |
List all images |
docker pull [OPTIONS] <image> |
Pull an image from a registry |
docker rmi [OPTIONS] <image> |
Remove an image |
docker build -t <tag> . |
Build an image from a Dockerfile |
docker push <image> |
Push an image to a registry |
Common Options for docker pull
| Option | Description |
|——–|————-|
| -a
| Pull all tagged images in the repository |
Networking
Command | Description |
---|---|
docker network ls |
List networks |
docker network create [OPTIONS] <network> |
Create a network |
docker network inspect <network> |
Inspect a network |
docker network rm <network> |
Remove a network |
Common Options for docker network create
| Option | Description |
|——–|————-|
| --driver <driver>
| Specify the network driver |
| --subnet <subnet>
| Set a subnet for the network |
Volumes
Command | Description |
---|---|
docker volume ls |
List volumes |
docker volume create [OPTIONS] <volume> |
Create a volume |
docker volume inspect <volume> |
Inspect a volume |
docker volume rm <volume> |
Remove a volume |
Common Options for docker volume create
| Option | Description |
|——–|————-|
| --label <key>=<value>
| Set metadata for a volume |
System Information
Command | Description |
---|---|
docker info |
Display system-wide information |
docker version |
Show Docker version information |
docker stats |
Display live resource usage statistics |
Logs and Inspection
Command | Description |
---|---|
docker logs [OPTIONS] <container> |
Fetch the logs of a container |
docker inspect <container/image> |
Return low-level information |
docker exec -it <container> bash |
Run a command in a running container |
Common Options for docker logs
| Option | Description |
|——–|————-|
| -f
| Follow log output |
| --tail <number>
| Number of lines to show from the end of the logs |