Logo

dev-resources.site

for different kinds of informations.

Top 20 Docker Commands with Examples and Outputs

Published at
1/15/2025
Categories
docker
cli
tutorial
devops
Author
omerberatsezer
Categories
4 categories in total
docker
open
cli
open
tutorial
open
devops
open
Author
14 person written this
omerberatsezer
open
Top 20 Docker Commands with Examples and Outputs

Important Docker commands with their outputs:

docker pull

  • downloads an image from Docker registry
user@docker:$ docker pull nginx:latest # download latest tag
Using default tag: latest
latest: Pulling from library/nginx
a480a496ba95: Pull complete
Digest: sha256:28402db69fec7c17e179ea87882667
Status: Downloaded newer image for nginx:latest
docker.o/library/nginx:latest
Enter fullscreen mode Exit fullscreen mode

docker run

  • runs a container from an image
user@docker:$ docker run -d -p 8080:80 nginx:latest
# -d => run in detach mode (background)
# -p => publish port  <host>:<container>
8f9f97dc08ffddb173ebe61eaa871b2944
Enter fullscreen mode Exit fullscreen mode

docker ps

  • lists all running containers
user@docker:$ docker ps
user@docker:$ docker ps -a
CONTAINER ID  IMAGE               COMMAND                     CREATED            STATUS                      
8f9f97dc08ff     nginx:latest     "/docker-entrypoint"   2 minutes ago   Up 2 minutes 
Enter fullscreen mode Exit fullscreen mode

docker images

  • lists all downloaded images
user@docker:$ docker images
REPOSITORY      TAG        IMAGE ID            CREATED             SIZE
nginx                     latest     3b25b682ea82   4 weeks ago     192MB
Enter fullscreen mode Exit fullscreen mode

docker rm

  • removes a stopped container
user@docker:$ docker container rm -f my_container
8f9
user@docker:$ docker image rm -f nginx            # force to delete image
Untagged: nginx:latest
Untagged: nginx@sha256:28402db69fec7c17e179ea8788266
Deleted: sha256:3b25b682ea82b2db3cc4fd48db818be788ee
Deleted: sha256:3e8a4396bcdb62aeb916ec1e4cf645000380
Enter fullscreen mode Exit fullscreen mode

docker rmi

  • removes a specific image
user@docker:$ docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:28402db69fec7c17e179ea8788266
Deleted: sha256:3b25b682ea82b2db3cc4fd48db818be788ee
Deleted: sha256:3e8a4396bcdb62aeb916ec1e4cf645000380
Enter fullscreen mode Exit fullscreen mode

docker exec

  • runs a command inside a running container
user@docker:$ docker exec -it my_container bash
user@docker:$ docker exec -it my_container bin/sh
# pwd
/
# read escape sequence      # CTRL + P + Q => go to host
user@docker:$
Enter fullscreen mode Exit fullscreen mode

docker build

  • builds an image from a Dockerfile
user@docker:$ docker build -t myapp .    
# if Dockerfile in the same directory
user@docker:$ docker build -t myapp -f /other-directory/Dockerfile .
# if Dockerfile in the different directory path
Enter fullscreen mode Exit fullscreen mode

docker logs

  • shows logs from a container
user@docker:$ docker logs my_container
2024/11/01 21:20:08 [notice] 1#1: nginx/1.27.2
2024/11/01 21:20:08 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
2024/11/01 21:20:08 [notice] 1#1: OS: Linux 5.10.60.1
Enter fullscreen mode Exit fullscreen mode

docker network ls

  • lists all networks
user@docker:$ docker network ls
NETWORK ID     NAME        DRIVER    SCOPE
19cb6e2b2cab   bridge       bridge    local
8ab407104066   host           host      local
67944d3050a3   none          null      local
Enter fullscreen mode Exit fullscreen mode

docker volume ls

  • lists all volumes
user@docker:$ docker volume ls
DRIVER    VOLUME NAME
local          3a243556537e4e11
local          myvolume
Enter fullscreen mode Exit fullscreen mode

docker login

  • login dockerhub or docker registry
user@docker:$ docker login
Login with your Docker ID to push and pull images from Docker Hub.
Username:
Password:
Enter fullscreen mode Exit fullscreen mode

docker tag

  • creates a new tag for an image, useful for renaming or versioning
user@docker:$ docker tag nginx:latest my_nginx:latest
REPOSITORY    TAG            IMAGE ID                CREATED           SIZE
my_nginx           latest        3b25b682ea82      4 weeks ago     192MB
nginx                   latest        3b25b682ea82      4 weeks ago     192MB
Enter fullscreen mode Exit fullscreen mode

docker push

  • uploads an image to Docker Hub or another Docker registry
user@docker:$ docker push <my_username>/my_nginx
The push refers to repository [docker.io/<my_username>/my_nginx]
e4e9e9ad93c2: Mounted from library/nginx
latest: digest: sha256:7ba542bde95e6523a4b126f610 size: 1778
Enter fullscreen mode Exit fullscreen mode

docker save

  • saves a Docker image as a .tar archive
user@docker:$ docker save -o <imageName>.tar  <imageName>
user@docker:$ docker save -o my_nginx.tar my_nginx
user@docker:$  ls
my_nginx.tar
Enter fullscreen mode Exit fullscreen mode

docker load

  • loads an image from a .tar archive
user@docker:$ docker load -i my_image.tar
user@docker:$ docker load -i my_nginx.tar
Loaded image: my_nginx:latest
Enter fullscreen mode Exit fullscreen mode

docker stats

  • displays real-time resource usage statistics for containers
user@docker:$ docker stats
CONTAINER ID   NAME      CPU %     MEM USAGE / LIMIT   MEM %     NET I/O   BLOCK I/O   PIDS
Enter fullscreen mode Exit fullscreen mode

docker-compose up

  • starts and runs all services defined in a docker-compose.yml file
user@docker:$ docker-compose up -d      
# -d => run detach mode, background
Enter fullscreen mode Exit fullscreen mode

docker-compose down

  • stops and removes all services and networks created by docker-compose up
user@docker:$ docker-compose down
Enter fullscreen mode Exit fullscreen mode

docker system prune

  • cleans up unused containers, images, networks, and volumes
user@docker:$ docker system prune
user@docker:$ docker system prune -a
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all images without at least one container associated to them
  - all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers: 94eabb9dd32f55061bc3d6
Enter fullscreen mode Exit fullscreen mode
devops Article's
30 articles in total
DevOps bridges the gap between development and operations, emphasizing collaboration, automation, and continuous delivery in software development.
Favicon
Day 04: Docker Compose: Managing multi-container applications
Favicon
AWS Certification Syllabus [Updated 2025]
Favicon
Research DevOps metrics and KPIs
Favicon
Kafka server with SASL_OAUTHBEARER
Favicon
Introduction to Terraform: Revolutionizing Infrastructure as Code
Favicon
Amazon S3 vs. Glacier: Data Archival Explained
Favicon
Be sure to check out our new bug bounty platform!
Favicon
Làm thế nào để quản lý secrets hiệu quả trên nhiều nền tảng chỉ với một công cụ?
Favicon
Как создать свой VPN и получить доступ ко всему?
Favicon
Building a Weather Data Collection System with AWS S3 and OpenWeather API
Favicon
Terraform input validation
Favicon
NXP i.MX8MP Platform Porting Driver Tutorial
Favicon
Stop Worrying About EC2 Patching – Automate It Like a Pro!
Favicon
How Pinterest uses Kafka for Long-Term Data Storage
Favicon
Something You Didn't Know About AWS Availability Zones
Favicon
Advanced Load Balancing with Traefik: An Introduction to Progressive Delivery, Mirroring, Sticky Sessions, and Health Checks
Favicon
Psychotherapy Technology Advancements
Favicon
Any recommendations of open source asset inventory ?
Favicon
AIOps : Investigation par l’IA dans Kubernetes avec HolmesGPT, Ollama et RunPod …
Favicon
How to Solve Common Kubernetes Multi-Cluster Deployment Issues
Favicon
Power Up Your AWS Game: Create EC2 Instances, Install Apache, and Connect with PowerShell
Favicon
Effortless vCluster Management with Sveltos: An Event-Driven Approach
Favicon
Docker vs kubernetes
Favicon
🚀 Week 3 Recap: Learning in Public – Software Engineering with DevOps 🚀
Favicon
HashiCorp Vault Setup Guide for NEAR Protocol Accounts
Favicon
Mastering Kubernetes Storage: A Deep Dive into Persistent Volumes and Claims
Favicon
Configuring Public IP addresses in Azure
Favicon
SPL: a database language featuring easy writing and fast running
Favicon
Cloud computing can be confusing, but it doesn't have to be! ☁️🤔 In the latest episode of Cloud in List of Threes (CiLoTs), I’m serving up easy-to-digest (pun intended 🤭) explanations analogy to explain Regions, Availability Zones, and Edge Locations
Favicon
[Boost]

Featured ones: