Sitemap

Docker commands

3 min readJan 20, 2025

--

Comprehensive list of Docker commands categorized by their purpose. These commands cover a wide range of operations for managing Docker containers, images, networks, and volumes.

Basic Docker Commands

  • docker — version: Display the installed Docker version.
  • docker info: Display system-wide information about Docker.
  • docker help: Get help on Docker commands.

Container Management

  • docker run [options] IMAGE [COMMAND] [ARG…]: Run a container from an image.
  • docker ps: List running containers.docker ps -a: List all containers (running and stopped).docker ps -q: List only container IDs.
  • docker start CONTAINER: Start a stopped container.
  • docker stop CONTAINER: Stop a running container.
  • docker restart CONTAINER: Restart a container.
  • docker pause CONTAINER: Pause a running container.
  • docker unpause CONTAINER: Unpause a paused container.
  • docker kill CONTAINER: Kill a running container.
  • docker rm CONTAINER: Remove a stopped container.docker rm -f CONTAINER: Force-remove a running container.
  • docker logs CONTAINER: View logs of a container.docker logs -f CONTAINER: Follow the logs.
  • docker exec [options] CONTAINER COMMAND: Execute a command in a running container.
  • docker attach CONTAINER: Attach your terminal to a running container.
  • docker top CONTAINER: Display running processes in a container.
  • docker inspect CONTAINER: Get detailed information about a container.
  • docker stats: Display resource usage statistics of containers.

Image Management

  • docker images: List Docker images.docker images -q: List only image IDs.
  • docker pull IMAGE: Download an image from Docker Hub or a registry.
  • docker push IMAGE: Push an image to Docker Hub or a registry.
  • docker build [options] PATH: Build an image from a Dockerfile.docker build -t NAME:TAG PATH: Build with a specific name and tag.
  • docker tag SOURCE_IMAGE TARGET_IMAGE: Tag an image with a new name.
  • docker rmi IMAGE: Remove an image.docker rmi -f IMAGE: Force-remove an image.
  • docker history IMAGE: View the history of an image.
  • docker inspect IMAGE: Get detailed information about an image.
  • docker save IMAGE > FILE.tar: Save an image to a tar file.
  • docker load < FILE.tar: Load an image from a tar file.

Get Zayed Hamadi’s stories in your inbox

Join Medium for free to get updates from this writer.

Network Management

  • docker network ls: List all Docker networks.
  • docker network create NETWORK_NAME: Create a new network.
  • docker network inspect NETWORK_NAME: Get details of a specific network.
  • docker network connect NETWORK_NAME CONTAINER: Connect a container to a network.
  • docker network disconnect NETWORK_NAME CONTAINER: Disconnect a container from a network.
  • docker network rm NETWORK_NAME: Remove a network.

Volume Management

  • docker volume ls: List all Docker volumes.
  • docker volume create VOLUME_NAME: Create a new volume.
  • docker volume inspect VOLUME_NAME: Get details of a specific volume.
  • docker volume rm VOLUME_NAME: Remove a volume.
  • docker volume prune: Remove all unused volumes.

Swarm and Services

  • docker swarm init: Initialize a swarm.
  • docker swarm join: Join a swarm as a worker node.
  • docker service create [options] IMAGE [COMMAND]: Create a new service.
  • docker service ls: List services in the swarm.
  • docker service inspect SERVICE: Get detailed information about a service.
  • docker service scale SERVICE=REPLICAS: Scale a service to the specified number of replicas.
  • docker service rm SERVICE: Remove a service.

Docker Compose

  • docker-compose up: Create and start containers defined in a docker-compose.yml file.docker-compose up -d: Run containers in detached mode.
  • docker-compose down: Stop and remove containers, networks, and volumes created by docker-compose up.
  • docker-compose ps: List containers managed by Docker Compose.
  • docker-compose logs: View logs of services managed by Docker Compose.
  • docker-compose exec SERVICE COMMAND: Execute a command in a service’s container.
  • docker-compose build: Build or rebuild services.
  • docker-compose restart SERVICE: Restart a specific service.

System Management

  • docker system df: Show Docker disk usage.
  • docker system prune: Remove unused data (containers, images, volumes, and networks).
  • docker system info: Display system-wide Docker information.

Container Copying

  • docker cp SOURCE DEST: Copy files/folders between a container and the host.

--

--

Zayed Hamadi
Zayed Hamadi

Written by Zayed Hamadi

A passionate Web developer from Tunisia