In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about what the Docker command is about. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Brief introduction
The commands of Docker are divided into use commands and management commands, and this paper summarizes the use commands and management commands of Docker, so as to facilitate others to learn and review and use them.
Docker not only provides commands to be used in all aspects, but also provides DockerAPI for us to use Http to interact with Docker to develop our own Docker.
Because there are too many commands, the following is a rough list for you to have a preliminary understanding of all the commands, and then where will not click.
Management command: container management container image management mirror network management network node management Swarm node plugin management plug-in secret management Docker secrets service management service stack management Docker stacks swarm management Swarm cluster system view system information volume management volume such as: docker container ls shows all containers general command: / / developers should be proficient in: images view image list rmi delete image save will specify image protection Save as tar archive file load from archive or STDIN load image build from a DockerFile build image commit create an image create from container create a container run create a new container and run a command rename rename container start start container stop stop container restart restart container rm delete container logs get a container's log exec run the command cp in the running container Copy files between container and host file system ps to view container list / / what operators should be proficient in: login logs in docker image warehouse logout exits docker image warehouse search searches for images from Docker Hub pull pulls images push from image warehouse and uploads local images to image warehouse To log in to the image repository tag to mark the local image Classify it into a repository export export the container's file system as tar archive import create an image info display system-wide information version display Docker version information stats display (real-time) container resource usage statistics inspect display low-level information of Docker objects (view object details) diff display changes on the container file system (view container changes) events display Get real-time events from the server (see docker changes) port display port maps or specific mapping lists of containers (port view) top displays processes running in a container (view processes) history displays mirrored history attach enters a running container pause pauses all processes in one or more containers unpause restores all processes in the container kill kill running container wait blocking until the container stops Then print the exit code update to update the container configuration image repository login
Dockerlogin: log in to a Docker image repository. If the image repository address is not specified, it defaults to the official repository Docker Hub.
Docker logout: log out of a Docker image repository. If the image repository address is not specified, it defaults to the official repository Docker Hub.
Syntax:
Docker login/logout (- $) [SERVER]
-u login user name
-p login password
Example:
Log in to Docker Hub
Docker login-u username-p password
Log out of Docker Hub
Docker logoutpull
Dockerpull: pull or update the specified image from the image repository
Syntax:
Docker pull (- $) NAME [: TAG | @ DIGEST]
-aMagall pulls all tagged images
-- disable-content-trust ignores the verification of the image and enables it by default
Example:
Download the latest java image from Docker Hub.
Docker pull java
Download all images whose REPOSITORY is java from Docker Hub.
Docker pull-a javapush
Docker push: to upload a local image to the image repository, log in to the image repository first.
Syntax:
Docker push (- $) NAME [: TAG]
-- disable-content-trust ignores the verification of the image and enables it by default
Example:
Upload the local image myapache:v1 to the image repository
Docker push myapache:v1
Push the mirror library to a private source
Docker push 192.168.0.100:5000/ubuntusearch
Docker search: finding images from Docker Hub
Syntax:
Docker search (- $) TERM
-automated lists only images of automated build type
-- no-trunc displays a complete description of the image
-s lists images with no less than the specified number of favorites.
Example:
Find all images from Docker Hub whose names contain java and have more than 10 favorites
Docker search-s 10 javarunoob@runoob:~$ docker search-s 10 javaNAME DESCRIPTION STARS OFFICIAL AUTOMATEDjava Java is a concurrent, class-based... 1037 [OK] anapsix/alpine-java Oracle Java 8 (and 7) with GLIBC. 115 [OK] develar/java 46 [OK] isuper/java-oracle This repository contains all java... 38 [OK] lwieske/java-8 Oracle Java 8 Container-Full +. 27 [OK] nimmis/java-centos This is docker images of CentOS 7. 13 [OK] Local Image Management images
Docker images: lists the local images.
Syntax:
Docker images (- $) [REPOSITORY [: TAG]]
-a lists all local mirrors (including intermediate image layers, which are filtered by default)
-- digests displays summary information of the image
-f displays mirrors that meet the criteria
-- format specifies the template file of the returned value
-- no-trunc displays complete image information
-Q displays only the mirror ID.
Example:
Find out the useless mirror image
Docker images-f dangling=true
Lists the local images whose REPOSITORY is alpine.
Docker images alpine [root@master ~] # docker images alpineREPOSITORY TAG IMAGE ID CREATED SIZEalpine 3.9 cdf98d1859c1 3 months ago 5.53MBalpine latest cdf98d1859c1 3 months ago 5.53MBrmi
Docker rmi: delete one or more local images.
Syntax:
Docker rmi (- $)
-fforce force force to delete the image
-- no-prune does not remove the process image of the mirror, but removes it by default
Example:
Delete all mirrors
Docker rmi $(docker images-Q)
Force the deletion of a mirror containing "doss-api" in its name
Docker rmi-- force $(docker images | grep doss-api | awk'{print $3}')
Delete useless images in batches (you can delete them in all three ways. If you want to delete them forcefully, add-f after rmi)
Docker rmi $(docker images | grep "^" | awk "{print $3}") docker images | grep none | awk'{print $3}'| xargs docker rmidocker rmi $(docker images-f dangling=true) tag
Docker tag: Mark the local image and put it in a repository.
Syntax:
Docker tag (- $) IMAGE [: TAG] [REGISTRYHOST/] [USERNAME/] NAME [: TAG]
Example:
Mark the mirror ubuntu:15.10 as a runoob/ubuntu:v3 mirror.
Docker tag ubuntu:15.10 runoob/ubuntu:v3root@runoob:~# docker tag ubuntu:15.10 runoob/ubuntu:v3root@runoob:~# docker images runoob/ubuntu:v3REPOSITORY TAG IMAGE ID CREATED SIZErunoob/ubuntu v3 4e3b13c8a266 3 months ago 136.3 MBbuild
The docker build command is used to create a mirror using Dockerfile.
Syntax:
Docker build (- $) PATH | URL |-
-- build-arg= [] sets the variable when the image is created
-- cpu-shares sets the cpu use weight
-- cpu-period limits CPU CFS cycles
-- cpu-quota limits CPU CFS quotas
-- CPU id specified by cpuset-cpus
-- cpuset-mems specifies the memory id used
-- disable-content-trust ignores verification and is enabled by default
-f specify the Dockerfile path to be used
-- delete intermediate containers during force-rm setting mirroring
-- isolation uses container isolation technology
-- label= [] sets the metadata used by the mirror
-m sets the maximum memory value
-- memory-swap sets the maximum value of Swap to memory + swap, and "- 1" means unlimited swap
-- no-cache does not use caching in the process of creating a mirror
-- pull attempts to update the new version of the image
-- quiet,-Q quiet mode. Only image ID is output after success.
-- delete the intermediate container after the rm setting image is successful
-- shm-size sets the size of / dev/shm. The default is 64m.
-- ulimit Ulimit configuration.
-- tag,-t image name and tag, usually in name:tag or name format; you can set multiple tags for an image in a build.
-- network defaults to default. Set the network mode of the RUN instruction during the build
Example:
Create an image using the Dockerfile of the current directory, labeled runoob/ubuntu:v1.
Docker build-t runoob/ubuntu:v1.
Create a mirror using URL github.com/creack/docker-firefox 's Dockerfile.
Docker build github.com/creack/docker-firefox
You can also use the location of the-f Dockerfile file:
Docker build-f / path/to/a/Dockerfile.
Before the Docker daemon executes the instructions in Dockerfile, it first performs a syntax check on Dockerfile, and returns if there is a syntax error:
Docker build-t test/myapp. Sending build context to Docker daemon 2.048 kB Error response from daemon: Unknown instruction: RUNCMDhistory
Docker history: view the creation history of the specified image.
Syntax:
Docker history (- $) IMAGE
-H prints the image size and date in a readable format, default to true
-- no-trunc displays the complete submission record
-Q lists only the submission record ID.
Save
Docker save: saves the specified image as a tar archive file.
Syntax:
Docker save (- $) IMAGE [IMAGE...]
-o the file to which you output.
Example:
Export Mirror
Docker save-o / root/mytomcat7.tar.gz docker.io/tomcat:7.0.77-jre7
Or
Docker save docker.io/tomcat:7.0.77-jre7 > / root/mytomcat7.tar.gzload
Docker load: import images exported using the docker save command.
Syntax:
Docker load (- $)
-I specifies the exported file.
-Q simplify the output information.
Example
Import Mirror
Docker load-I ubuntu.tardocker load
< ubuntu.tardocker load < /root/mytomcat7.tar.gz import docker import : 从归档文件中创建镜像。 语法: docker import (-$) file|URL|- [REPOSITORY[:TAG]] -c,--change 将Dockerfile指令应用于创建的映像 -m,--message 为导入的镜像设置说明信息 --platform 如果服务器具有多平台功能,则设置平台 实例 从镜像归档文件my_ubuntu_v3.tar创建镜像,命名为runoob/ubuntu:v4 runoob@runoob:~$ docker import my_ubuntu_v3.tar runoob/ubuntu:v4 sha256:63ce4a6d6bc3fabb95dbd6c561404a309b7bdfc4e21c1d59fe9fe4299cbfea39runoob@runoob:~$ docker images runoob/ubuntu:v4REPOSITORY TAG IMAGE ID CREATED SIZErunoob/ubuntu v4 63ce4a6d6bc3 20 seconds ago 142.1 MB容器操作ps dockerps : 列出容器 语法: docker ps (-$) -a, --all 显示所有容器(默认显示正在运行) -n 显示最后创建的n个容器(包括所有状态)(默认值-1) 示例:docker ps -n2 -l,--latest 显示最新创建的容器(包括所有状态) -q, --quiet 只显示数字id -s, --size 显示总文件大小 --no-trunc 不截断输出 -f, --filter 根据提供的条件过滤输出 过滤条件如下: Filter | Description ---|--- id | 容器的ID name | 容器的Name label | 表示键或键值对的任意字符串。表示为或= exited | 表示容器退出代码的整数。只有对所有人有用。 status | created,restarting,running,removing,paused,exited,dead之一 ancestor| 筛选指定镜像的容器,例如[:],, or before or since | 筛选在给定容器ID或名称之前或之后创建的容器 volume | 运行已挂载给定卷或绑定挂载的容器的筛选器。 network | 过滤器运行连接到给定网络的容器。 publish or expose | 筛选发布或公开给定端口的容器,例如[/] or /[] health | 根据容器的健康检查状态过滤容器,例如starting, healthy, unhealthy or none. isolation | 仅Windows守护进程,例如default, process, or hyperv. is-task | 筛选服务的"任务"容器。布尔选项(true or false) 示例: docker ps -f name=^'modality' docker ps --filter name=nginx docker ps -a --filter exited=0 docker ps --filter status=running docker ps --filter expose=3306 --format 使用Go模板漂亮地打印容器 过滤条件如下: Placeholder | Description ---|--- .ID | 容器的ID .Image | 镜像的ID .Command | 引用命令 .CreatedAt | 创建容器的时间 .RunningFor | 自容器启动以来的运行时长 .Ports | 暴露的端口 .Status | 容器状态 .Size | 容器的磁盘大小 .Names | 容器的名称 .Labels | 分配给容器的所有标签 .Label | 此容器的特定标签的值,例如`{{.Label "com.docker.swarm.cpu"}}` .Mounts | 容器挂载的卷 .Networks | 容器所用的网络名称 示例: docker ps --format "{{.ID}}: {{.Names}}: {{.Command}}" 常用监控命令: 查询最近5个容器 docker ps -a -n=5 监控容器数量 docker ps -a -q | wc -l 正在运行的容器的数量 docker ps -q | wc -l 非运行状态的容器的数量 docker ps -a | grep -v 'Up ' | grep -v'CONTAINER' | wc -linspect docker inspect : 获取容器/镜像的元数据。 语法: docker inspect (-$) NAME|ID [NAME|ID...] -f 使用给定的Go模板格式化输出 -s 如果类型是容器,则显示总文件大小 --type 为指定类型返回JSON。 实例: 查看容器重启次数 docker inspect -f "{{ .RestartCount }}" name 查看容器最后一次的启动时间 docker inspect -f "{{ .State.StartedAt }}" name 列出所有端口绑定 docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} ->{{(index $conf 0) .HostPort}} {{end}}'$INSTANCE_ID
Get the IP of the running container mymysql
Runoob@runoob:~$ docker inspect-- format=' {{range .NetworkSettings.Networks}} {{.IPAddress}} {{end}} 'mymysql172.17.0.3
Note: for more examples, please click on the link on the official website above.
Top
Docker top: view the process information running in the container and support ps command parameters.
Syntax:
Docker top CONTAINER [ps OPTIONS]
The container runtime does not necessarily have / bin/bash terminals to interactively execute top commands, and the container does not necessarily have top commands, so you can use docker top to view the running processes in the container.
Example:
View the process information of the container mymysql.
Runoob@runoob:~/mysql$ docker top mymysqlUID PID PPID C STIME TTY TIME CMD999 40347 40331 18 00:58? 00:00:02 mysqld
View the process information for all running containers.
For i in docker ps | grep Up | awk'{print $1}'; do echo & & docker top $I; done
Attach
Docker attach: connect to a running container and attach local standard input, output, and error streams to the running container (for personal understanding, use commands to control the container after linking)
Syntax:
Docker attach (- $) CONTAINER
-- detach-keys overrides the key sequence used to separate the container
-- no-stdin does not attach STDIN
-- all process signals received by sig-proxy Agent (default is true)
The container you want to attach on must be running, and you can connect the same container at the same time to share the screen (similar to the attach of the screen command).
The official document says that you can detach through CTRL-C after attach, but in fact, after my test, if container is currently running bash,CTRL-C is naturally the input of the current line, without exiting; if container is currently running a process in the foreground, such as outputting nginx's access.log log, CTRL-C will not only cause you to exit the container, but also stop it. This is not what we want, detach should mean to leave the container terminal, but the container is still running. Fortunately, attach can carry-sig-proxy=false to ensure that CTRL-D or CTRL-C does not close the container.
Example:
Container mynginx points the access log to standard output and connects to the container to view access information.
Runoob@runoob:~$ docker attach-- sig-proxy=false mynginx192.168.239.1-- [10/Jul/2016:16:54:26 + 0000] "GET / HTTP/1.1" 3040 "-" Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36 ""-"
Note: (the container also stops running after exiting with exit). For more examples and details, please click on the link on the official website above or use the-- help command to view
Events
Docker events: getting real-time events from the server
Syntax:
Docker events (- $)
-fmaine Murray filter filters events based on conditions
-- format formats the output using the given Go template
-- since displays all events from the specified timestamp
-- until pipelining time is displayed until the specified time
Example:
Shows all events of docker since July 1, 2016.
Docker events-since= "1467302400" runoob@runoob:~/mysql$ docker events-since= "1467302400" 2016-07-08T19:44:54.501277677+08:00 network connect 66f958fd13dc4314ad20034e576d5c5eba72e0849dcc38ad9e8436314a4149d4 (container=b8573233d675705df8c89796a2c2687cd8e36e03646457a15fb51022db440e64, name=bridge, type=bridge) 07-08T19:44:54.723876221+08:00 container start b8573233d675705df8c89796a2c2687cd8e36e03646457a15fb51022db440e64 (image=nginx:latest, name=elegant_albattani)
Shows that the docker image is mysql:5.6 related events after July 1, 2016.
Docker events-f "image" = "mysql:5.6"-- since= "1467302400" runoob@runoob:~/mysql$ docker events-f "image" = "mysql:5.6"-since= "1467302400" 2016-07-11T00:38:53.975174837+08:00 container start 96f7f14e99ab9d2f60943a50be23035eda1623782cc5f930411bbea407a2bb10 (image=mysql:5.6, name=mymysql) 2016-07-11T00:51:17.022572452+08:00 container kill 96f7f14e99ab9d2f60943a50be23035eda1623782cc5f930411bbea407a2bb10 (image=mysql:5.6, name=mymysql, signal=9)
Note: for more examples and detailed instructions, please click the link on the official website above or use the-- help command to view.
Logs
Docker logs: get the log of the container
Docker logs (- $) name
-- details displays additional details provided to the log
-freguency, talk, follow, track log output
-- since displays logs after a timestamp (e.g. 2013-01-02T13:23:37) or relatively (e.g. 42 minutes and 42 seconds)
The time stamp of the time stamp is similar to that of tail-f.
-- tail outputs the specified number of rows of logs at the end of the log (default for all logs)
-- until displays logs before the timestamp (e.g. 2013-01-02T13:23:37) or relatively (e.g. 42 minutes and 42 seconds)
Example:
Check the latest 10 logs of container mynginx since July 1, 2016.
Docker logs-since= "2016-07-01"-tail=10 mynginx
View docker container logs in real time
Docker logs-f-t-- tail number of rows container name
View the last 10 lines of log of the docker container named S12 in real time
Docker logs-f-t-- tail 10 S12
Note: for more examples and detailed instructions, please click the link on the official website above or use the-- help command to view.
Wait
Docker wait: block running until the container stops, and then print out its exit code.
Syntax:
Docker wait (- $) CONTAINER [CONTAINER...]
Example
Docker wait CONTAINERexport
Docker export: export the file system to STDOUT as a tar archive
Syntax:
Docker export [OPTIONS] CONTAINER
The input content is written to the file.
Example:
Example 1: save the container named red_panda as a tar file
Docker export red_panda > latest.tar
Or
Docker export-output= "latest.tar" red_panda
Example 2: save the container whose id is a404c6c174a2 as a tar file by date.
Runoob@runoob:~$ docker export-o mysql- `date +% Y% m% d`.tar a404c6c174a2runooblastomyrunoobana $ls mysql- `ql +% Y% m% d`.tarmysql-20160711.tarport
Docker port: lists the port mappings for the specified container, or looks for ports that PRIVATE_PORT NAT to the public.
Syntax:
Docker port CONTAINER [PRIVATE_ PORT[ / PROTO]]
Example:
Check the port mapping for which the container ID is cbe08f2a4406.
Runoob@runoob:~$ docker port cbe08f2a44063306/tcp-> 0.0.0.0:13306stats
Docker stats: a real-time stream that displays container resource usage statistics
Syntax:
Docker stats (- $) [CONTAINER...]
-amam Mustel all shows all containers (the default shows that it has just run)
-- format beautifully printed images using Go templates
-- no-stream disables streaming statistics and extracts only the first result
-- no-trunc do not truncate the output
Example:
Run all containers that docker stats is running against the Linux daemon.
$docker statsCONTAINER ID NAME CPU% MEM USAGE / LIMIT MEM% NET I BLOCK O PIDSb95a83497c91 awesome_brattain 0.28% 5.629MiB / 1.952GiB 0.28% 916B / 0B 147kB / 0B 967b2525d8ad1 foobar 0.00% 1.727MiB / 1.952GiB 0.09% 2.48kB / 0B 4.11MB / 0B 2e5c383697914 test-1951.1.kay7x1lh2twk9c0oig50sd5tr 0.00% 196KiB / 1.952GiB 0.01% 71.2kB / 0B 770kB / 0B 14bda148efbc0 random.1.vnc8on831idyr42slu578u3cr 0.005% 1.672MiB / 1.952GiB 0.08%
If the specified format string, format, is not used, the following is displayed.
Column names describe the ID and name of the CONTAINER ID and Name containers CPU% and MEM% the percentage of host CPU and memory in use by the MEM USAGE / LIMIT container the total memory being used by the MEM USAGE / LIMIT container and the total amount of data sent and received by the BLOCK I container through its network interface the number of processes or threads created by the PIDs container to read and write data from block devices on the host
Note: for more examples, please click on the link on the official website above.
Container Lifecycle Management run
Docker run: create a new container and run a command
Note: since the number of options for this command is as high as 99, only some commonly used options are selected in this section. For details, please see the official website.
Syntax:
Docker run (- $) IMAGE [COMMAND] [ARG...]
-a,-- attach= [] specifies the standard input and output content type, optional STDIN/STDOUT/STDERR three items, used to log in to the container (must be a container started with docker run-d)
-d runs the container in the background and returns the container ID. Default is false.
-I opens STDIN and runs the container in interactive mode. It is usually used with-t. Default is false.
-P,-- publish-all=false random port mapping, the port inside the container is randomly mapped to each port of the host
-p,-- publish= [] specify the port exposed by the container. Format: host (host) port: container port
The container is reassigned with a pseudo-input terminal TTY to support terminal login, which is usually used with-I and defaults to false.
-- name= "" specifies the container name, which is required for the links feature.
-u,-- user= "" specifies the user of the container
-w specify the working directory of the container
-c sets the container CPU weight, which is used in the CPU shared scene
-e,-- env= [] specifies the environment variable, which can be used in the container
-m specifies the upper memory limit of the container
-h specify the hostname of the container
-v,-- volume= [] Mount the storage volume to the container and mount it to a directory of the container
-- volumes-from= [] mounts volumes on other containers to the container and mounts it to a directory of the container
-- cap-add= [] add permissions
-- cap-drop= [] removes permissions
After cidfile= "" runs the container, the container pid value is written in the specified file to monitor the system usage.
-- cpuset= "" sets which CPU can be used by the container. This parameter can be used for the container to monopolize CPU.
-- device= [] add a host device to the container, which is equivalent to a direct connection of the device
-- dns= [] specifies the dns server of the container
-- dns-search= [] specifies the dns search domain name of the container, which is written to the container / etc/resolv.conf file
-- entrypoint= "" overrides the entry point of image
-- env-file= [] specifies the environment variable file in the format of one environment variable per line
-- expose= [] opens a port or a group of ports, that is, to modify the exposed port of the image.
-- link= [] specifies the association between containers to link to another container, thus using the IP, env, and other information of other containers
-- lxc-conf= [] specifies the configuration file of the container, which can only be used when-- exec-driver=lxc is specified.
-- net= "bridge" specifies the network connection type of the container:
Bridge uses the bridge specified by docker daemon
Host / / Container uses the host's network
Container:NAME_or_ID > / / use other containers to share network resources such as IP and PORT
None containers use their own network (similar to-- net=bridge)
-- privileged=false specifies whether the container is a privileged container, which has all permissions
-- restart= "no" specifies the restart policy after the container is stopped:
No: do not restart when the container exits (default policy)
On-failure: restart when a container failure exits (the return value is non-zero)
On-failure:3, restart the container when it exits abnormally, up to 3 times
Always: always restart the container when it exits
Unless-stopped: always restart the container when it exits, but do not consider the container that was stopped when the Docker daemon started
-- rm=false specifies that containers are automatically deleted when they are stopped (containers started with docker run-d are not supported)
-- sig-proxy=true settings are accepted and processed by the agent, but not by SIGCHLD,SIGSTOP and SIGKILL
Extension description: exit status code of the container
The exit status code of docker run is as follows:
0, indicating normal exit
Non-0, indicating abnormal exit (the exit status code is chroot standard) the error of the ◦ 125 Docker daemon itself
126, after the container starts, the default command to be executed cannot be called
127, after the container starts, the default command to be executed does not exist
For other command status codes, the command is executed normally after the container starts, and the return status code of the command is used as the exit status code of the container when exiting the command.
Example:
Use the docker mirror nginx:latest to start a container in background mode and name the container mynginx.
Docker run-- name mynginx-d nginx:latest
Use mirrored nginx:latest to start a container in background mode and map the container's port 80 to the host random port.
Docker run-P-d nginx:latest
Using mirror nginx:latest, start a container in background mode, mapping port 80 of the container to port 80 of the host, and the directory / data of the host to the / data of the container.
Docker run-p 80:80-v / data:/data-d nginx:latest
Bind port 8080 of the container and map it to port 80 of the local host 127.0.0.1.
Docker run-p 127.0.0.1:80:8080/tcp ubuntu bash
Use the mirror nginx:latest to start a container in interactive mode and execute the / bin/bash command inside the container.
Runoob@runoob:~$ docker run-it nginx:latest / bin/bashroot@b8573233d675:/#start/stop/restart
Docker start: start one or more containers that have been stopped
Docker stop: stop a running container
Docker restart: restart the container
Syntax:
Docker start (- $) CONTAINER [CONTAINER...]
-- attach,-a connects to STDOUT / STDERR and forwards the signal
-- checkpoint restores from this checkpoint
-- checkpoint-dir uses custom checkpoints to store directories
-- detach-keys overrides the key sequence used to separate the container
-- interactive,-I attach the STDIN of the container
Docker stop (- $) CONTAINER [CONTAINER...]
-- time,-t the number of seconds to wait to stop before killing. Default is 10 seconds.
Docker restart (- $) CONTAINER [CONTAINER...]
-- time,-t the number of seconds to wait to stop before killing. Default is 10 seconds.
Kill
Docker kill: kill a running container.
Syntax:
Docker kill (- $) CONTAINER [CONTAINER...]
A signal is sent to the container to force the interrupt-s to represent the specified SIGINT signal type. The default is "kill".
Example:
Kill the running container mynginx
Runoob@runoob:~$ docker kill-s KILL mynginxmynginx
Kill all running containers
Docker kill $(docker ps-p-a)
Note: the-s in this section involves the signal of Linux. For more information, please click here to view
Rm
Docker rm: delete one or more containers
Syntax:
Docker rm (- $) CONTAINER [CONTAINER...]
-f-- force=false forcibly deletes a running container through a SIGKILL signal
-l-- link=false removes the network connection between containers, not the container itself, leaving the underlying container
-v-- volumes=false deletes the volume associated with the container
Example:
Remove the connection of container nginx01 to container db01, connection name db
Docker rm-l db
Delete the container nginx01 and delete the data volumes mounted by the container
Docker rm-v nginx01
Force deletion of all containers
Docker rm-f 'docker ps-a-Q'
Delete non-running containers
Docker rm docker ps-a-f status=exited
Delete the container that exits abnormally
Docker rm docker ps-a | grep Exited | awk' {print $1}'
One command to deactivate and delete the container
Docker stop $(docker ps-Q) & docker rm $(docker ps-aq)
Delete the last 5 containers in batch
Docker rm $(docker ps-aq-nasty 5)
Remove the container created by the specified image
Docker rm $(docker ps-a | grep "watch-the-fun/jdk:8" | awk'{print $1}')
Command split explanation:
| | pipe character, which is mainly used to pass the execution result of the previous command as a parameter to the next command |
Docker ps-a queries all created containers (including unstarted)
Grep "watch-the-fun/jdk:8" filter mirrors a record named watch-the-fun/jdk:8
Awk'{print $1} 'looks up the first column in the record by row, which is the id of the container
$() is used as command replacement
Note: for more examples and detailed instructions, please click the link on the official website above or use the-- help command to view.
Pause/unpause
Docker pause: pauses all processes in the container.
Docker unpause: restores all processes in the container.
Syntax:
Docker pause CONTAINER [CONTAINER...] docker unpause CONTAINER [CONTAINER...]
Example:
Suspend the service provided by database container db01
Docker pause db01
Restore database container db01 services
Docker unpause db01create
Docker create: create a new container without starting it
The usage is the same as docker run
Syntax:
Docker create (- $) IMAGE [COMMAND] [ARG...]
Syntax is the same as docker run
Example:
Create a container using the docker image nginx:latest and name the container myrunoob
Runoob@runoob:~$ docker create-name myrunoob nginx:latest 09b93464c2f75b7b69f83d56a9cfc23ceb50a48a9db7652ee4c27e3e2cb1961fexec
Docker exec: execute commands in the running container
Syntax:
Docker exec (- $) CONTAINER COMMAND [ARG...]
-dmam Meltel detach mode: running commands in the background
Keep STDIN open even if you don't have a connection
-tmam Murty assigns a pseudo terminal (TTY)
-- detach-keys overrides the key sequence used to separate the container
-e _ mam _ r _ env sets environment variables
-- privileged provides extended permissions for commands
-- user,-u user name or UID (format: [:])
The working directory in the container of wjmmem copyright workdir
Example:
Example 1: execute the intra-container / root/runoob.sh script in the container mynginx in interactive mode:
Runoob@runoob:~$ docker exec-it mynginx / bin/sh / root/runoob.sh http://www.runoob.com/
Example 2: open an interactive mode terminal in the container mynginx:
Runoob@runoob:~$ docker exec-it mynginx / bin/bashroot@b1a0703e41e7:/#
Note: you can also use the docker ps-a command to view the containers that are already running, and then use the container ID to enter the container
Example 3: the 9df70f9a0714 in the first column is the container ID.
Bash the specified container through the exec command:
# docker exec-it 9df70f9a0714 / bin/bash
Note: this command is used to enter a container interactively (the container does not stop running after exiting using exit). For more details, please see the official website
Update
Docker update: update the configuration of one or more containers
Syntax:
Docker update (- $) CONTAINER [CONTAINER...]
-- blkio-weight blocks IO (relative weight), between 10 and 1000, or 0 block (default is 0)
-- the period during which cpu-period restricts CPU CFS (fully Fair Planning procedure)
-- cpu-quota limits CPU CFS (fully fair scheduler) quotas
-- cpu-rt-period limits CPU real-time cycles (in microseconds)
-- cpu-rt-runtime limits real-time running time of CPU in microseconds
-- cpu-shares,-c CPU share (relative weight)
-- number of cpus CPU
-- CPU allowed to be executed by cpuset-cpus (0-3Jing 0Pol 1)
-- MEM allowed to be executed by cpuset-mems (0-3Jing 0Pol 1)
-- kernel-memory kernel memory limit
-- memory,-m memory limit
-- memory-reservation memory soft limit
-- memory-swap swap limit equals memory plus swapping:'- 1 to enable unlimited swapping
-- restart restart the policy applied when the container exits
Example:
Update the cpu-shares of the container
To limit the cpu-shares of a container to 512, first identify the container name or ID. You can use it to docker ps to find these values. You can also use the ID returned from the docker run command. Then, do the following:
Docker update-- cpu-shares 512 abebf7571666
Update the container with cpu-shares and memory
To update multiple resource configurations for multiple containers:
Docker update-- cpu-shares 512-m 300m abebf7571666 hopeful_morse
Note: for more examples, please click on the link on the official website above.
Container rootfs Command commit
Docker commit: create a new image from the container.
Syntax:
Docker commit (- $) CONTAINER [REPOSITORY [: TAG]]
-a ~ the author.
The Dockerfile instruction is used to create the mirror image
-mmam Murray message = "" A brief description
-pmam Meltel pauseworthy true pauses the container during submission
Example:
Save the container a404c6c174a2 as a new image and add the author information and description information.
Runoob@runoob:~$ docker commit-a "runoob.com"-m "my apache" a404c6c174a2 mymysql:v1 sha256:37af1236adef1544e8886be23010b66577647a40bc02c0885a6600b33ee28057runoob@runoob:~$ docker images mymysql:v1REPOSITORY TAG IMAGE ID CREATED SIZEmymysql v1 37af1236adef15 seconds ago 329 MBcp
Docker cp: used for copying data between the container and the host.
Syntax:
Docker cp (- $) CONTAINER:SRC_PATH DEST_PATH |-docker cp (- $) SRC_PATH |-CONTAINER:DEST_PATH
-amam Musi archive archive mode (copy all uid / gid information)
The link in the source and destination is maintained by the Lremand, the music, the follower, the
Example:
Example 1: copy the host / www/runoob directory to the / www directory of container 96f7f14e99ab
Docker cp / www/runoob 96f7f14e99ab:/www/
Example 2: copy the host / www/runoob directory to the container 96f7f14e99ab and rename the directory to www
Docker cp / www/runoob 96f7f14e99ab:/www
Example 3: copy the / www directory of container 96f7f14e99ab to the / tmp directory of the host
Docker cp 96f7f14e99ab:/www / tmp/diff
Docker diff: check for changes to files or directories on the container file system
Syntax:
Docker diff CONTAINER
Extension description
Lists the files and directories that have changed in the container file system since the container was created. Track three different types of changes:
Symbol description An added file or directory D file or directory deleted C file or directory changed
Example:
View the file structure changes of the container mymysql
Runoob@runoob:~$ docker diff mymysqlA / logsA / mysql_dataC / runC / run/mysqldA / run/mysqld/mysqld.pidA / run/mysqld/mysqld.sockC / tmprename
Docker rename: rename a container
Syntax:
Docker rename CONTAINER NEW_NAMEdocker management command
In addition to the above usage commands, Docker also provides a series of administrative commands, which are as follows
Builder management construction
Config manages Docker configuration
Container management container
Engine manages the docker engine
Image Management Mirror
Network management network
Node manages Swarm nodes
Plugin Management snap-in
Secret Management Docker secrets
Service Management Service
Stack manages the Docker stack
Swarm manages Swarm clusters
System View system Information
Trust manages trust in Docker images
Volume manages volumes
We don't have to know all the above commands like the back of our hand, because it's a waste of time, but we can know what they do, just check the official website when needed.
The following is a list of the administrative commands we often use:
View a list of networks
Docker network ls
View swarm service list
Docker service ls
Delete all images that are not marked by tag and not used by the container
$docker image prune WARNING! This will remove all dangling images. Are you sure you want to continue? [y/N] y
Delete all images that are not used by the container:
Docker image prune-a
Delete all containers that are not running:
Docker container prune
Delete all unmounted volumes:
Docker volume prune
Delete all networks:
Docker network prune
Delete all docker resources:
Docker system prune
Trim the mirror:
Docker system prune-aDocker option docker (- $)
-- api-enable-cors=false enables CORS headers in remote API
-b,-- bridge= "" bridging network disables container network using "none"
-- bip= "" bridge mode
-d,-- daemon=false Guardian mode
-D,-- debug=false debug mode
-- dns= [] forces docker to use a specified dns server
-- dns-search= [] forces docker to use the specified dns search domain
-e,-- exec-driver= "native" forces the docker runtime to use the specified execution drive
-- fixed-cidr= "" fixed IP IPv4 subnets (for example: 10.20.0.0 IP 16) must be embedded in the bridge subnet (defined by-b or-- bip)
-G,-- group= "docker" when running in daemon mode, the group points to the unix socket specified by-H. Use "" to disable group settings.
-g,-- the root directory path where the graph= "/ var/lib/docker" container is running
-H,-- host= [] socket binds to daemon mode. Use one or more tcp:// hosts: ports, unix:/// paths / to / sets, fd://* or fd://socketfd.
-- icc=true inter-container cross-container communication
-- insecure-registry= [] enables unsecure communication using the specified registry (certificate verification without HTTPS and enabling HTTP fallback) (for example, localhost:5000 or 10.20.0 / 16)
-- IP address used when binding container ports to ip= "0.0.0.0"
-- ip-forward=true uses net.ipv4.ip_forward to forward
-- ip-masq=true makes IP disguise as the IP range of the bridge
-- iptables=true enables Docker to add iptables rules
-- mtu=0 sets the container network mtu
-p,-- pidfile= "/ var/run/docker.pid" specifies the daemon pid file location
-- registry-mirror= [] specifies a preferred image repository (acceleration address)
-s,-- storage-driver= "" forces the docker runtime to use the specified storage driver
-- selinux-enabled=false enables selinux support
-- storage-opt= [] sets storage driver options
-- tls=false enables tls
-- tlscacert= "/ root/.docker/ca.pem" trusts only certificates that provide CA signature
-- tlscert= "/ root/.docker/cert.pem" tls certificate file location
-- tlskey= "/ root/.docker/key.pem" tlskey file location
-- tlsverify=false uses tls and confirms remote control of the host
-v,-- version=false outputs docker version information
Thank you for reading! This is the end of this article on "what are the Docker commands?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.