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
docker Article's
30 articles in total
Building bun-tastic: A Fast, High-Performance Static Site Server (OSS)
read article
Day 04: Docker Compose: Managing multi-container applications
read article
Infraestrutura para anΓ‘lise de dados com Jupyter, Cassandra, Pyspark e Docker
read article
Building RelaxTube: A Scalable Video Transcoding and Streaming Application
read article
Docker vs kubernetes
read article
Advanced Docker Concepts and Features
read article
Building and Deploying Your First Java App with Docker in Just 5 Minutes
read article
Realtime troubleshooting based questions docker compose
read article
common Docker Compose interview questions.
read article
[Boost]
read article
Docker scenario
read article
TOP 10 TYPES OF DOCKER COMMANDS
read article
how to inspect a docker container
read article
How to run a Nginx-web server
read article
Docker article Best
read article
Load Balancing Node.js Applications with Nginx Upstream Configuration
read article
Top 20 Docker Commands with Examples and Outputs
currently reading
π Deploying a Live Project Without a Dockerfile Using Buildpacks π
read article
A Conversation with Docker CTO Justin Cormack and Flux CEO Ron Efrani: The Future of Developer Environments
read article
Understanding Node.js Alpine Versions: A Lightweight Choice for Your Projects
read article
Day 03: Docker Images and Containers: Building, Pulling, and Running Docker Containers
read article
How would you optimize the performance of Docker containers, particularly in resource-constrained environments ?
read article
Docker in development: Episode 4
read article
Building a Local S3 Environment with MinIO: AWS SDK for Java V2 Migration Guide
read article
Node.js Meets PostgreSQL and MongoDB in Docker: Docker Diaries
read article
How to Use Docker in Your Data Science Projects: A Complete Guide
read article
Bringing Together Containers & SQL
read article
π Are Your Docker Containers Secure? π‘οΈ In this article, learn 10 actionable strategies to protect your Docker containers like a pro
read article
Running PostgreSQL, MongoDB, and NestJS concurrently with Docker Compose
read article
Creando un notebook con Jupyter y Kotlin
read article
Featured ones: