ToolStack
KO

Docker Commands Cheatsheet

Docker commands for images, containers, and Docker Compose

Your data never leaves the browser — all processing is done locally 0 server requests

01

Images

  • docker pull nginx:latest

    Download an image from a registry

  • docker images

    List locally available images

  • docker build -t myapp:1.0 .

    Build an image from the Dockerfile in the current directory

  • docker rmi 이미지명

    Remove an image

  • docker image prune -a

    Remove all unused images ※ use with caution

  • docker tag myapp:1.0 user/myapp:1.0

    Tag an image with a new name (registry path)

  • docker push user/myapp:1.0

    Push an image to a registry

02

Running Containers

  • docker run -d -p 8080:80 --name web nginx

    Run in background and map host port 8080 to container port 80

  • docker run -it --rm ubuntu bash

    Open a shell in a temporary container, auto-removed on exit

  • docker run -e KEY=value 이미지

    Run a container with an environment variable injected

  • docker run -v $(pwd):/app 이미지

    Mount the current directory into the container at /app

  • docker run --restart unless-stopped 이미지

    Automatically restart the container when Docker restarts

03

Container Management

  • docker ps

    List running containers (-a includes stopped ones)

  • docker stop web

    Gracefully stop a container (start/restart also available)

  • docker rm web

    Remove a stopped container (-f force-removes a running one)

  • docker container prune

    Remove all stopped containers at once

  • docker rename old new

    Rename a container

04

Debugging

  • docker logs -f --tail 100 web

    Stream logs live starting from the last 100 lines

  • docker exec -it web bash

    Open a shell inside a running container (use sh if bash is unavailable)

  • docker inspect web

    Show detailed container configuration (IP, mounts, etc.) as JSON

  • docker stats

    Show real-time CPU and memory usage per container

  • docker cp web:/var/log/nginx/access.log ./

    Copy a file from the container to the host

  • docker port web

    Show the port mappings of a container

05

Volumes & Networks

  • docker volume ls

    List volumes (create/rm/inspect also available)

  • docker volume prune

    Remove unused volumes ※ data will be deleted

  • docker network ls

    List networks

  • docker network create mynet

    Create a custom network (containers can communicate by name)

  • docker network connect mynet web

    Connect a running container to a network

06

Docker Compose

  • docker compose up -d

    Start all services in compose.yaml in the background

  • docker compose down

    Stop services and remove containers and networks (-v also removes volumes ※ caution)

  • docker compose ps

    Check the status of services

  • docker compose logs -f 서비스명

    Stream logs for a specific service in real time

  • docker compose build --no-cache

    Rebuild images without using cache

  • docker compose exec 서비스명 bash

    Open a shell inside a service container

  • docker compose restart 서비스명

    Restart a specific service

07

System Cleanup

  • docker system df

    Show disk usage by images, containers, and volumes

  • docker system prune

    Remove stopped containers, unused networks, and dangling images

  • docker system prune -a --volumes

    Remove all unused resources ※ irreversible, proceed with caution

  • docker builder prune

    Clear the build cache

Docker: Containers from Build to Production

Docker packages applications and their dependencies into portable containers. The basic workflow is: write a Dockerfile → docker build to create an image → docker run to start a container. Images are immutable; containers are running instances of images.

docker compose simplifies multi-container setups with a YAML file. docker compose up -d starts all services in the background and docker compose down stops and removes them.

⚠ docker system prune -a and docker volume prune can delete data that is difficult to recover. Always back up important volumes before pruning.

FAQ

What is the difference between docker stop and docker kill?
docker stop sends SIGTERM to the container, giving it time to shut down gracefully (default 10-second timeout). docker kill sends SIGKILL immediately, which forces termination without cleanup. Always prefer docker stop first.
How do I see the logs of a running container?
Use docker logs <container-id-or-name>. Add -f to follow live output (like tail -f) and --since 1h to limit to the last hour. For Docker Compose, use docker compose logs -f service-name.
How do I clean up unused Docker resources?
docker system prune removes all stopped containers, unused networks, dangling images, and build cache. Add -a to also remove unused images (not just dangling). Run docker system df first to see how much space you can reclaim.

Related Tools