Skip to main content

Docker Cheats

Cheat sheet for Docker commands.

info

This page was automatically generated from a navi cheat file available at difranca/navi-cheats.
Navi is an interactive cheatsheet tool for the command-line. To learn more about it, visit denisidoro/navi.


Imagesโ€‹

Build and manage images.

CommandDescription
docker build -t {tag} .Build an image from a Dockerfile
docker build -t {tag} -f {dockerfile} .Build an image from a specific Dockerfile
docker imagesList images
docker rmi {image}Remove an image
docker pull {image_name}Pull an image from a registry
docker tag {image} {new_tag}Tag an image
docker image pruneRemove all dangling images

Containersโ€‹

Run and manage containers.

CommandDescription
docker run -d --name {name} {image}Run a container in detached mode
docker run -d -p {host_port}:{container_port} {image}Run a container with port mapping
docker run -d -v {host_path}:{container_path} {image}Run a container with volume mount
docker run -it {image} /bin/shRun an interactive container with shell
docker psList running containers
docker ps -aList all containers
docker stop {container}Stop a running container
docker start {all_container}Start a stopped container
docker restart {container}Restart a container
docker rm {all_container}Remove a stopped container
docker exec -it {container} /bin/shExecute a command in a running container
docker logs {container}View container logs
docker logs -f {container}Follow container logs
docker logs --since {duration} {container}Show container logs since a time period
docker inspect {container}Inspect a container
docker cp {container}:{container_path} {host_path}Copy files from container to host
docker cp {host_path} {container}:{container_path}Copy files from host to container

Volumesโ€‹

Manage persistent data.

CommandDescription
docker volume lsList volumes
docker volume create {name}Create a volume
docker volume rm {volume}Remove a volume
docker volume pruneRemove all unused volumes

Networkโ€‹

Manage container networking.

CommandDescription
docker network lsList networks
docker network create {name}Create a network
docker network inspect {network}Inspect a network
docker network connect {network} {container}Connect a container to a network
docker network disconnect {network} {container}Disconnect a container from a network

Composeโ€‹

Manage multi-container applications.

CommandDescription
docker compose up -dStart services in detached mode
docker compose up -d --buildStart services with build
docker compose downStop services
docker compose down -vStop services and remove volumes
docker compose logsView service logs
docker compose logs -fFollow service logs
docker compose psList running services
docker compose build {service_name}Rebuild a specific service
docker compose restart {service_name}Restart a specific service

Cleanupโ€‹

Free up disk space.

CommandDescription
docker system pruneRemove all stopped containers, unused networks, dangling images, and build cache
docker system dfShow docker disk usage