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
Author
14 person written this
omerberatsezer
open
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
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
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
docker images
- lists all downloaded images
user@docker:$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 3b25b682ea82 4 weeks ago 192MB
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
docker rmi
- removes a specific image
user@docker:$ docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:28402db69fec7c17e179ea8788266
Deleted: sha256:3b25b682ea82b2db3cc4fd48db818be788ee
Deleted: sha256:3e8a4396bcdb62aeb916ec1e4cf645000380
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:$
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
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
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
docker volume ls
- lists all volumes
user@docker:$ docker volume ls
DRIVER VOLUME NAME
local 3a243556537e4e11
local myvolume
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:
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
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
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
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
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
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
docker-compose down
- stops and removes all services and networks created by docker-compose up
user@docker:$ docker-compose down
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
devops Article's
30 articles in total
DevOps bridges the gap between development and operations, emphasizing collaboration, automation, and continuous delivery in software development.
Day 04: Docker Compose: Managing multi-container applications
read article
AWS Certification Syllabus [Updated 2025]
read article
Research DevOps metrics and KPIs
read article
Kafka server with SASL_OAUTHBEARER
read article
Introduction to Terraform: Revolutionizing Infrastructure as Code
read article
Amazon S3 vs. Glacier: Data Archival Explained
read article
Be sure to check out our new bug bounty platform!
read article
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ụ?
read article
Как создать свой VPN и получить доступ ко всему?
read article
Building a Weather Data Collection System with AWS S3 and OpenWeather API
read article
Terraform input validation
read article
NXP i.MX8MP Platform Porting Driver Tutorial
read article
Stop Worrying About EC2 Patching – Automate It Like a Pro!
read article
How Pinterest uses Kafka for Long-Term Data Storage
read article
Something You Didn't Know About AWS Availability Zones
read article
Advanced Load Balancing with Traefik: An Introduction to Progressive Delivery, Mirroring, Sticky Sessions, and Health Checks
read article
Psychotherapy Technology Advancements
read article
Any recommendations of open source asset inventory ?
read article
AIOps : Investigation par l’IA dans Kubernetes avec HolmesGPT, Ollama et RunPod …
read article
How to Solve Common Kubernetes Multi-Cluster Deployment Issues
read article
Power Up Your AWS Game: Create EC2 Instances, Install Apache, and Connect with PowerShell
read article
Effortless vCluster Management with Sveltos: An Event-Driven Approach
read article
Docker vs kubernetes
read article
🚀 Week 3 Recap: Learning in Public – Software Engineering with DevOps 🚀
read article
HashiCorp Vault Setup Guide for NEAR Protocol Accounts
read article
Mastering Kubernetes Storage: A Deep Dive into Persistent Volumes and Claims
read article
Configuring Public IP addresses in Azure
read article
SPL: a database language featuring easy writing and fast running
read article
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
read article
[Boost]
read article
Featured ones: