This website requires JavaScript.
Docker image

Docker commands essentials

Some useful Docker commands for managing containers and images.

6 min read
Updated: Feb 05, 2025

Commands for managing containers

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

Commands for managing images

CommandDescriptiondocker imagesList all imagesdocker pull <image>Pull an image from a registrydocker rmi <image>Remove an imagedocker rmi -f <image>Force remove an imagedocker build -t <image-name> <path>Build an image from a Dockerfiledocker tag <image> <new-image>Tag an imagedocker push <image>Push an image to a registrydocker save <image> -o <file.tar>Save an image to a tar filedocker load -i <file.tar>Load an image from a tar file

Commands for managing networks

CommandDescriptiondocker network lsList all networksdocker network create <network>Create a networkdocker network rm <network>Remove a networkdocker network inspect <network>Display detailed information about a networkdocker network connect <network> <container>Connect a container to a networkdocker network disconnect <network> <container>Disconnect a container from a network

Commands for managing volumes

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

Commands for cleaning up resources

CommandDescriptiondocker system pruneRemove all stopped containers, unused networks, and dangling imagesdocker system prune -aRemove all stopped containers, unused networks, and all imagesdocker container pruneRemove all stopped containersdocker image pruneRemove all dangling imagesdocker network pruneRemove all unused networksdocker volume pruneRemove all unused volumes

Commands for managing Docker Compose

CommandDescriptiondocker-compose upStart services defined in a docker-compose.yml filedocker-compose downStop services defined in a docker-compose.yml filedocker-compose psList servicesdocker-compose logsDisplay logs of servicesdocker-compose exec <service> <command>Execute a command in a servicedocker-compose buildBuild servicesdocker-compose pushPush services to a registrydocker-compose pullPull services from a registrydocker-compose configValidate and view the docker-compose.yml filedocker-compose imagesList images used by servicesdocker-compose stopStop services without removing containersdocker-compose restartRestart servicesdocker-compose rmRemove stopped containersdocker-compose down -vRemove containers and volumesdocker-compose up -dStart services in detached modedocker-compose exec <service> bashExecute a shell in a service

Commands for managing Docker Swarm

CommandDescriptiondocker swarm initInitialize a swarmdocker swarm joinJoin a swarmdocker node lsList nodes in a swarm

Commands for managing Docker secrets

CommandDescriptiondocker secret createCreate a secretdocker secret lsList secretsdocker secret inspectDisplay detailed information about a secretdocker secret rmRemove a secret

Commands for managing Docker configs

CommandDescriptiondocker config createCreate a configdocker config lsList configsdocker config inspectDisplay detailed information about a configdocker config rmRemove a config

Commands for managing Docker services

CommandDescriptiondocker service lsList servicesdocker service createCreate a servicedocker service inspectDisplay detailed information about a servicedocker service updateUpdate a servicedocker service scaleScale a servicedocker service rmRemove a servicedocker service logsDisplay logs of a servicedocker service psList tasks of a servicedocker service update --forceForce update a servicedocker service update --rollbackRollback a service updatedocker service update --rollback-parallelismSet the number of tasks to rollback in paralleldocker service update --rollback-delaySet the delay between task rollbacksdocker service update --rollback-monitorSet the duration to monitor a rollbackdocker service update --rollback-max-failure-ratioSet the maximum failure ratio for a rollbackdocker service update --rollback-orderSet the order of tasks to rollback

Commands for managing Docker stacks

CommandDescriptiondocker stack deployDeploy a stackdocker stack lsList stacksdocker stack servicesList services in a stackdocker stack psList tasks in a stackdocker stack rmRemove a stackdocker stack deploy --compose-fileDeploy a stack using a Compose filedocker stack deploy --with-registry-authDeploy a stack with registry authenticationdocker stack deploy --prunePrune services that are no longer defined in the Compose filedocker stack deploy --resolve-imageResolve the image digest for services in the Compose file

Commands for managing Docker plugins

CommandDescriptiondocker plugin lsList pluginsdocker plugin installInstall a plugindocker plugin enableEnable a plugindocker plugin disableDisable a plugindocker plugin rmRemove a plugindocker plugin upgradeUpgrade a plugindocker plugin pushPush a plugin to a registrydocker plugin pullPull a plugin from a registry
  • docker
  • devops
Database Replication strategy in large systems
Jul 20, 2025
Some useful Dockerfile templates
Apr 08, 2025

🍃 Related posts