This website requires JavaScript.
Docker image

Docker commands essentials

Some useful Docker commands for managing containers and images.

6 min read

I. Commands for managing containers

CommandDescription
docker versionShow the Docker version information
docker infoDisplay system-wide information
docker run <image>Run a container from an image
docker run -d <image>Run a container in detached mode
docker psList running containers
docker ps -aList all containers
docker stop <container>Stop a running container
docker start <container>Start a stopped container
docker restart <container>Restart a container
docker rm <container>Remove a container
docker rm -f <container>Force remove a container (real-time ouput)
docker logs <container>Display logs of a container
docker logs -f <container>Follow logs of a container
docker inspect <container>/<image>Display detailed information about a container
docker exec -it <container> bashExecute a command in a running container
docker cp <container>:<path> <host-path>Copy files between container and host
docker commit <container> <image>Create an image from a container
docker attach <container>Attach to a running container
docker pause <container>Pause a running container
docker unpause <container>Unpause a paused container
docker top <container>Display the running processes of a container
docker stats <container>Display a live stream of container resource usage
docker diff <container>Show changes to files in a container's filesystem
docker rename <container> <new-name>Rename a container
docker export <container> -o <file.tar>Export a container's filesystem to a tar file
docker import <file.tar> <image>Import a tar file as an image

II. Commands for managing images

CommandDescription
docker imagesList all images
docker pull <image>Pull an image from a registry
docker rmi <image>Remove an image
docker rmi -f <image>Force remove an image
docker build -t <image-name> <path>Build an image from a Dockerfile
docker tag <image> <new-image>Tag an image
docker push <image>Push an image to a registry
docker save <image> -o <file.tar>Save an image to a tar file
docker load -i <file.tar>Load an image from a tar file

III. Commands for managing networks

CommandDescription
docker network lsList all networks
docker network create <network>Create a network
docker network rm <network>Remove a network
docker network inspect <network>Display detailed information about a network
docker network connect <network> <container>Connect a container to a network
docker network disconnect <network> <container>Disconnect a container from a network

IV. Commands for managing volumes

CommandDescription
docker volume lsList all volumes
docker volume create <volume>Create a volume
docker volume rm <volume>Remove a volume
docker volume inspect <volume>Display detailed information about a volume
docker run -v <volume>:<path> <image>Mount a volume to a container

V. Commands for cleaning up resources

CommandDescription
docker system pruneRemove all stopped containers, unused networks, and dangling images
docker system prune -aRemove all stopped containers, unused networks, and all images
docker container pruneRemove all stopped containers
docker image pruneRemove all dangling images
docker network pruneRemove all unused networks
docker volume pruneRemove all unused volumes

VI. Commands for managing Docker Compose

CommandDescription
docker-compose upStart services defined in a docker-compose.yml file
docker-compose downStop services defined in a docker-compose.yml file
docker-compose psList services
docker-compose logsDisplay logs of services
docker-compose exec <service> <command>Execute a command in a service
docker-compose buildBuild services
docker-compose pushPush services to a registry
docker-compose pullPull services from a registry
docker-compose configValidate and view the docker-compose.yml file
docker-compose imagesList images used by services
docker-compose stopStop services without removing containers
docker-compose restartRestart services
docker-compose rmRemove stopped containers
docker-compose down -vRemove containers and volumes
docker-compose up -dStart services in detached mode
docker-compose exec <service> bashExecute a shell in a service

VII. Commands for managing Docker Swarm

CommandDescription
docker swarm initInitialize a swarm
docker swarm joinJoin a swarm
docker node lsList nodes in a swarm

VIII. Commands for managing Docker secrets

CommandDescription
docker secret createCreate a secret
docker secret lsList secrets
docker secret inspectDisplay detailed information about a secret
docker secret rmRemove a secret

IX. Commands for managing Docker configs

CommandDescription
docker config createCreate a config
docker config lsList configs
docker config inspectDisplay detailed information about a config
docker config rmRemove a config

X. Commands for managing Docker services

CommandDescription
docker service lsList services
docker service createCreate a service
docker service inspectDisplay detailed information about a service
docker service updateUpdate a service
docker service scaleScale a service
docker service rmRemove a service
docker service logsDisplay logs of a service
docker service psList tasks of a service
docker service update --forceForce update a service
docker service update --rollbackRollback a service update
docker service update --rollback-parallelismSet the number of tasks to rollback in parallel
docker service update --rollback-delaySet the delay between task rollbacks
docker service update --rollback-monitorSet the duration to monitor a rollback
docker service update --rollback-max-failure-ratioSet the maximum failure ratio for a rollback
docker service update --rollback-orderSet the order of tasks to rollback

XI. Commands for managing Docker stacks

CommandDescription
docker stack deployDeploy a stack
docker stack lsList stacks
docker stack servicesList services in a stack
docker stack psList tasks in a stack
docker stack rmRemove a stack
docker stack deploy --compose-fileDeploy a stack using a Compose file
docker stack deploy --with-registry-authDeploy a stack with registry authentication
docker stack deploy --prunePrune services that are no longer defined in the Compose file
docker stack deploy --resolve-imageResolve the image digest for services in the Compose file

XII. Commands for managing Docker plugins

CommandDescription
docker plugin lsList plugins
docker plugin installInstall a plugin
docker plugin enableEnable a plugin
docker plugin disableDisable a plugin
docker plugin rmRemove a plugin
docker plugin upgradeUpgrade a plugin
docker plugin pushPush a plugin to a registry
docker plugin pullPull a plugin from a registry
  • Tags:
  • devops
  • docker
Feb 05, 2025
Previous page
SQL basics cheatsheet. Overview of SQL commands
Next page
Useful Dockerfile templates

šŸƒ Related posts