Docker basic commands
Today, review the basic commands of Docker. Redraw with reference to the classic Docker command picture on the Internet.
Image correlation
docker tag
Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
root@Yuan-Ubuntu:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE redis latest 5e25361b75a2 6 minutes ago 252MB Redis 6.2.0cc69ae189a1a 32 hours ago 105MB RabbitMQ latest 99720090a9d6 7 days ago 156MB centos latest 300e315adb2f 2 Months ago 209MB root@Yuan-Ubuntu:~# docker tag Redis :latest Redis :5.2 root@Yuan-Ubuntu:~# Docker images REPOSITORY tag IMAGE ID CREATED SIZE Redis 5.2 5E25361b75A2 6 minutes ago 252MB Redis latest 5E25361b75A2 6 minutes ago 252MB redis 6.2.0 CC69AE189a1a 32 hours ago 105MB RabbitMQ latest 99720090a9d6 7 days ago 156MB centos latest 300e315ADB2f 2 months ago 209MBCopy the code
docker build
Build an image from a Dockerfile
# DockerfileThe FROM centos RUN yum install - y wget RUN wget - O redis. Tar. Gz "http://download.redis.io/releases/redis-5.0.3.tar.gz" RUN tar -xvf redis.tar.gz FROM centos RUN yum install -y wget \ && wget -O redis.tar.gz "Http://download.redis.io/releases/redis-5.0.3.tar.gz" \ && tar XVF - redis. Tar. Gz
# docker build .
Copy the code
docker builder
Manage builds
docker commit
Create a new image from a container’s changes
docker pull
Pull an image or a repository from a registry
#Pulls the redis image of the specified versionroot@Yuan-Ubuntu:~# docker pull redis:6.2.0 6.2.0: Pulling from library/redis 45b42C59be33: pull complete 5ce2e937BF62: Pull complete 2a031498ff58: Pull complete 7407cbab5258: Pull complete c2d6c3b35be8: Pull complete 1997ce073dcd: Pull complete Digest: sha256:26bd5f3d2bbfb21d0e4f03d642570e63c8776d2a9e5963e4057280fb3b4e3e29 Status: Downloaded newer image for redis: 6.2.0 docker. IO/library/redis: 6.2.0Copy the code
docker push
Push an image or a repository to a registry
docker history
Show the history of an image
#You can see the historical process of image makingroot@Yuan-Ubuntu:~# docker history redis:6.2.0 IMAGE CREATED CREATED BY SIZE COMMENT cc69AE189a1A 30 hours ago /bin/sh -c #(nop) CMD ["redis-server"] 0B <missing> 30 hours ago /bin/sh -c #(nop) EXPOSE 6379 0B <missing> 30 hours ago /bin/sh -c #(nop) ENTRYPOINT ["docker-entry... 0B <missing> 30 hours ago /bin/sh -c #(nop) COPY file: df205A0EF6e6DF89... 374B <missing> 30 hours ago /bin/sh -c #(nop) WORKDIR /data 0B <missing> 30 hours ago /bin/sh -c #(nop) VOLUME [/data] 0B <missing> 30 hours ago /bin/sh -c mkdir /data && chown redis:redis... 0B <missing> 30 hours ago /bin/sh -c set-eux; savedAptMark="$(apt-m... 31.6MB <missing> 30 hours ago /bin/sh -c #(nop) ENV REDIS_DOWNLOAD_SHA=67... 0B <missing> 30 hours ago /bin/sh -c #(nop) ENV REDIS_DOWNLOAD_URL=ht... 0B <missing> 30 hours ago /bin/sh -c #(nop) ENV REDIS_VERSION= 6.2.0b <missing> 2 weeks ago /bin/sh -c set-eux; SavedAptMark = "$(apt - ma... 4.15MB <missing> 2 weeks ago /bin/sh -c #(nop) ENV GOSU_VERSION= 1.124b <missing> 2 weeks ago /bin/sh -c groupadd -r -g 999 redis && usera... 329kB <missing> 2 weeks ago /bin/sh -c #(nop) CMD ["bash"] 0B <missing> 2 weeks ago /bin/sh -c #(nop) ADD File: d5c41bfaf15180481... 69.2 MB root @ Yuan - Ubuntu: ~ #Copy the code
docker image
Manage images
#The command for managing mirrors is similar to other commands for managing mirrorsbuild Build an image from a Dockerfile history Show the history of an image import Import the contents from a tarball to create a filesystem image inspect Display detailed information on one or more images load Load an image from a tar archive or STDIN ls List images prune Remove unused images pull Pull an image or a repository from a registry push Push an image or a repository to a registry rm Remove one or more images save Save one or more images to a tar archive (streamed to STDOUT by default) tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGECopy the code
docker images
List images
#Viewing all mirrorsroot@Yuan-Ubuntu:~# Docker Images REPOSITORY TAG IMAGE ID CREATED SIZE Redis 6.2.0cc69ae189a1a 30 hours ago 105MB rabbitmq latest 99720090a9d6 7 days ago 156MB centos latest 300e315adb2f 2 months ago 209MBCopy the code
docker rmi
Remove one or more images
#Let's say I want to delete the Hello-world mirror
#Ensure that no container is using the image. Otherwise, the image cannot be deletedroot@Yuan-Ubuntu:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 12b047a4530f Redis :6.2.0 "Docker - entrypoint. S..." 8 minutes ago Exited (0) 24 seconds ago new_redis 103C9c8b827f redis:6.2.0 "docker-entrypoint.s..." 11 minutes ago Exited (0) 24 seconds ago stupefied_murdock 94d2cf2570c0 redis:6.2.0 "docker-entrypoint.s..." 13 minutes ago Exited (0) 24 seconds ago Dreamy_bassi 348aba2c17d4 Rabbitmq "docker-entrypoint.s..." 3 hours ago Exited (0) 19 seconds ago sleepy_goldstine 057AA2624bc3 Rabbitmq "docker-entrypoint.s..." 3 hours ago Exited (0) 19 seconds ago sleepy_cannon 4785044579f0 centos "/bin/bash" 3 hours ago Exited (0) 3 minutes ago funny_dhawan#Viewing all mirrorsroot@Yuan-Ubuntu:~# Docker Images REPOSITORY TAG IMAGE ID CREATED SIZE Redis 6.2.0cc69ae189a1a 30 hours ago 105MB rabbitmq latest 99720090a9d6 7 days ago 156MB centos latest 300e315adb2f 2 months ago 209MB hello-world latest Bf756fb1ae65 13 months ago 13.3kB#If there are multiple versions of an image, follow the following rule: Version number
root@Yuan-Ubuntu:~# docker rmi hello-world
Untagged: hello-world:latest
Untagged: hello-world@sha256:95ddb6c31407e84e91a986b004aee40975cb0bda14b5949f6faac5d2deadb4b9
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
Deleted: sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63
root@Yuan-Ubuntu:~#
Copy the code
docker save
Save one or more images to a tar archive (streamed to STDOUT by default)
docker search
Search the Docker Hub for images
#Find the image, the specific version of the dockerHub to findroot@Yuan-Ubuntu:~# docker search redis NAME DESCRIPTION STARS OFFICIAL AUTOMATED redis Redis is an open source The key value store - that... 9140 [OK] bitnami/redis Bitnami Redis Docker Image 173 [OK] sameersbn/redis 83 [OK] grokzen/redis-cluster Redis cluster Rediscommander/Redis-commander Alpine Image for Redis-commander-Redis Man... 54 [OK] Redisearch /redisearch Redis With the RedisSearch Module pre-loaded... 30 Redislabs/Redis Clustered In-memory Database Engine compatib... 27 redislabs/redisinsight RedisInsight - The GUI for Redis 25 oliver006/redis_exporter Prometheus Exporter for Redis The Metrics. Supp... 23 Redislabs /rejson RedisJSON - Enhanced JSON data Type processi... 23 arm32V7 /redis Redis is an open source key-value store that... 22 bitnami/redis-sentinel Bitnami Docker Image for Redis Sentinel 19 [OK] redislabs/redisgraph A graph database module for Redis 15 [OK] webhippie/redis Docker images for Redis 11 [OK] arm64v8/redis Redis is an open source key-value store That... 10 S7ANley/Redis-Sentinel-Docker Redis Sentinel 10 [OK] An automated Build of Automated... 9 [OK] insready/redis-stat Docker image for the real-time redis monitor... 9 [OK] goodsmileduck/redis-cli redis-cli on alpine 7 [OK] centos/redis-32-centos7 Redis in-memory data structure store, 2 a... 5 Circleci/Redis Circleci images for Redis 5 [OK] ClearLinux/Redis Redis key-value Data Structure Server with t... 3 Tiredofit/Redis Redis Server W/Zabbix Monitoring and S6 Ove... 1 [OK] wodby/redis Redis container image with orchestration 1 [OK] xetamus/redis-resource forked redis-resource 0 [OK]Copy the code
docker trust
Manage trust on Docker images
docker save
Save one or more images to a tar archive (streamed to STDOUT by default)
docker load
Load an image from a tar archive or STDIN
docker login
Log in to a Docker registry
docker logout
Log out from a Docker registry
The container related
docker attach
Attach local standard input, output, and error streams to a running container
root@Yuan-Ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 12b047a4530f Redis :6.2.0 "Docker - entrypoint. S..." 27 minutes ago Up 2 minutes 0.0.0.0:8000->6379/ TCP new_redis root@Yuan-Ubuntu:~# docker attach new_redisCopy the code
docker container
Manage containers
#A collection of commands that manage containers
attach Attach local standard input, output, and error streams to a running container
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
exec Run a command in a running container
export Export a container's filesystem as a tar archive
inspect Display detailed information on one or more containers
kill Kill one or more running containers
logs Fetch the logs of a container
ls List containers
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
prune Remove all stopped containers
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
run Run a command in a new container
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
wait Block until one or more containers stop, then print their exit codes
Copy the code
docker context
Manage contexts
docker cp
Copy files/folders between a container and the local filesystem
docker create
Create a new container
docker diff
Inspect changes to files or directories on a container’s filesystem
docker engine
Manage the docker engine
docker events
Get real time events from the server
docker exec
Run a command in a running container
root@Yuan-Ubuntu:~# docker exec 12b047a4530f ls
dump.rdb
Copy the code
docker export
Export a container’s filesystem as a tar archive
#export
root@Yuan-Ubuntu:~# docker export 12b047a4530f -o redis.tar
root@Yuan-Ubuntu:~# ls
redis.tar.gz snap
Copy the code
docker import
Import the contents from a tarball to create a filesystem image
docker info
Display system-wide information
#View docker system informationroot@Yuan-Ubuntu:~# docker info Client: Context: default Debug Mode: false Plugins: app: Docker App (Docker Inc., V0.9.1-beta3) buildx: Build with BuildKit (Docker Inc., v0.5.1-docker) Server: 6 Running: 0 Paused: 0 Stopped: 6 Images: 3 Server Version: 20.10.3 Storage Driver: Overlay2...Copy the code
docker inspect
Return low-level information on Docker objects
docker kill
Kill one or more running containers
root@Yuan-Ubuntu:~# docker kill 94d2cf2570c0 94d2cf2570c0 root@Yuan-Ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 348aba2C17d4 RabbitMQ "docker-entrypoint.s..." 2 hours ago Up 2 hours 4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/tcp sleepy_goldstineCopy the code
docker logs
Fetch the logs of a container
docker manifest
Manage Docker image manifests and manifest lists
docker network
Manage networks
root@Yuan-Ubuntu:~# docker network ls
NETWORK ID NAME DRIVER SCOPE
248a0a65a361 bridge bridge local
6ad3a44d85fe host host local
3a07c5f8816a none null local
Copy the code
docker plugin
Manage plugins
docker port
List port mappings or a specific mapping for the container
root@Yuan-Ubuntu:~# docker run -d -p 800:6379 --name my_redis redis:6.2.0 12b047a4530fc8edb9dff0cf6cf4120019f21a64c5b4b71a41e31913c68e50d2 root@Yuan-Ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 12b047A4530f REDis :6.2.0 "docker-entryPoint.s..." 8 seconds ago Up 5 seconds 0.0.0.0:8000->6379/ TCP my_redis 348aba2C17d4 RabbitMQ "docker-entrypoint.s..." 2 hours ago Up 2 hours 4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/ TCP sleepy_Goldstine root@Yuan-Ubuntu:~# docker port 12b047a4530f 6379/ TCP -> 0.0.0.0:8000Copy the code
docker run
Run a command in a new container
Root @ Yuan - Ubuntu: ~ # docker run - d redis: 94 d2cf2570c05f042f1f68e714c4472a7ba2db4276f8bd84eefbfdbc271e2f87 6.2.0Copy the code
docker ps
List containers
root@Yuan-Ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 94d2CF2570c0 redis:6.2.0 "Docker - entrypoint. S..." 26 seconds ago Up 23 seconds 6379/ TCP dreamy_bassi 348aba2c17d4 Rabbitmq "docker-entrypoint.s..." 2 hours ago Up 2 hours 4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/tcp sleepy_goldstineCopy the code
docker rename
Rename a container
#Rename my_redis to new_redisroot@Yuan-Ubuntu:~# docker rename 12b047a4530f new_redis root@Yuan-Ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 12b047A4530F Redis :6.2.0 "Docker-entryPoint.s..." 2 minutes ago Up 2 minutes 0.0.0.0:8000->6379/ TCP new_redis 348aba2c17d4 rabbitmq "docker-entrypoint.s..." 2 hours ago Up 2 hours 4369/tcp, 5671-5672/tcp, 15691-15692/tcp, 25672/tcp sleepy_goldstineCopy the code
docker restart
Restart one or more containers
#Restarting a single container
root@Yuan-Ubuntu:~# docker restart 12b047a4530f
12b047a4530f
#Restarting multiple containers
root@Yuan-Ubuntu:~# docker restart 12b047a4530f 348aba2c17d4
12b047a4530f
348aba2c17d4
#Restart all containers
root@Yuan-Ubuntu:~# docker restart $(docker ps -aq)
12b047a4530f
103c9c8b827f
94d2cf2570c0
348aba2c17d4
057aa2624bc3
4785044579f0
181b5b47f164
f44d1fc7839d
Copy the code
docker rm
Remove one or more containers
root@Yuan-Ubuntu:~# docker ps -aq
12b047a4530f
103c9c8b827f
94d2cf2570c0
348aba2c17d4
057aa2624bc3
4785044579f0
181b5b47f164
f44d1fc7839d
root@Yuan-Ubuntu:~# docker rm 181b5b47f164
181b5b47f164
root@Yuan-Ubuntu:~# docker ps -aq
12b047a4530f
103c9c8b827f
94d2cf2570c0
348aba2c17d4
057aa2624bc3
4785044579f0
f44d1fc7839d
root@Yuan-Ubuntu:~#
Copy the code
docker start
Start one or more stopped containers
root@Yuan-Ubuntu:~# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 12b047a4530f Redis :6.2.0 "Docker - entrypoint. S..." 21 minutes ago Exited (0) 13 minutes ago new_redis 103C9c8b827f redis:6.2.0 "Docker-entryPoint.s..." 25 minutes ago Exited (0) 13 minutes ago Stupefied_murdock 94d2cf2570c0 redis:6.2.0 "Docker-entrypoint.s..." 26 minutes ago Exited (0) 13 minutes ago Dreamy_bassi 348aba2c17d4 Rabbitmq "docker-entrypoint.s..." 3 hours ago Exited (0) 13 minutes ago sleepy_goldstine 057AA2624bc3 Rabbitmq "docker-entrypoint.s..." 3 hours ago Exited (0) 13 minutes ago sleepy_cannon 4785044579f0 centos "/bin/bash" 3 hours ago Exited (0) 16 minutes ago funny_dhawan root@Yuan-Ubuntu:~# docker start 12b047a4530f 12b047a4530f root@Yuan-Ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 12b047A4530f Redis :6.2.0 "docker-entryPoint.s..." 22 minutes ago Up 8 seconds 0.0.0.0:8000->6379/ TCP new_redisCopy the code
docker stats
Display a live stream of container(s) resource usage statistics
root@Yuan-Ubuntu:~# docker stats 12b047a4530f
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
12b047a4530f new_redis 0.22% 3.789MiB / 3.815GiB 0.10% 3.18kB / 0B 0B / 0B 5
Copy the code
docker stop
Stop one or more running containers
root@Yuan-Ubuntu:~# docker stop 12b047a4530f
12b047a4530f
Copy the code
docker system
Manage Docker
#You can view docker system disks, events, information, and more
df Show docker disk usage
events Get real time events from the server
info Display system-wide information
prune Remove unused data
Copy the code
docker top
Display the running processes of a container
root@Yuan-Ubuntu:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 12b047a4530f Redis :6.2.0 "Docker - entrypoint. S..." 53 minutes ago Up 23 minutes 0.0.0.0:8000->6379/ TCP new_redis root@Yuan-Ubuntu:~# docker top 12b047a4530f UID PID PPID C STIME TTY TIME CMD systemd+ 18126 18104 0 14:21 ? 00:00:03 redis-server *:6379Copy the code
docker pause
Pause all processes within one or more containers
docker unpause
Unpause all processes within one or more containers
docker update
Update configuration of one or more containers
Update the configuration of one or more containers, such as CPU, disk, and so onCopy the code
docker version
Show the Docker version information
docker volume
Manage volumes
docker wait
Block until one or more containers stop, then print their exit codes
That’s all for today! Thank you for reading! If this article is helpful, please give it a thumbs up