Docker命令集锦-容器操作命令

3、容器操作命令

3.1、容器命令汇总

描述(英文):Manage containers
描述(中文):管理容器
语法:docker container COMMAND
命令:

命令 英文说明&中文说明
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
将容器的文件系统导出为tar归档文件
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
阻塞,直到一个或多个容器停止,然后打印它们的退出代码
3.2、创建容器命令

描述(英文):Run a command in a new container
描述(中文):在新容器中运行命令
语法:docker container run [OPTIONS] IMAGE [COMMAND] [ARG...]
选项:

选项 英文说明&中文说明
--add-host list Add a custom host-to-IP mapping (host:ip)
添加自定义主机到ip的映射(主机:ip)
-a, --attach list Attach to STDIN, STDOUT or STDERR
连接到标准输入、标准输出或标准输入
--blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
块IO(相对权重),在10和1000之间,或0禁用(默认0)
--blkio-weight-device list Block IO weight (relative device weight) (default [])
块IO权值(相对设备权值)(默认[])
--cap-add list Add Linux capabilities
添加Linux功能
--cap-drop list Drop Linux capabilities
终止Linux功能
--cgroup-parent string Optional parent cgroup for the container
容器的可选父cgroup
--cidfile string Write the container ID to the file
将容器ID写入文件
--cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
限制CPU CFS(完全公平调度程序)周期
--cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
限制CPU CFS(完全公平调度程序)配额
--cpu-rt-period int Limit CPU real-time period in microseconds
限制CPU实时周期(以微秒为单位)
--cpu-rt-runtime int Limit CPU real-time runtime in microseconds
限制CPU实时运行时间(以微秒为单位)
-c, --cpu-shares int CPU shares (relative weight)
CPU份额(相对权重)
--cpus decimal Number of CPUs
CPU的数量
--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
允许执行的CPU (0- 3,0,1)
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
允许执行的MEMs (0- 3,0,1)
-d, --detach Run container in background and print container ID
在后台运行容器并打印容器ID
--detach-keys string Override the key sequence for detaching a container
覆盖用于分离容器的键序列
--device list Add a host device to the container
将主机设备添加到容器中
--device-cgroup-rule list Add a rule to the cgroup allowed devices list
在cgroup允许设备列表中添加一个规则
--device-read-bps list Limit read rate (bytes per second) from a device (default [])
限制从设备读取速率(每秒字节数)(默认[])
--device-read-iops list Limit read rate (IO per second) from a device (default [])
限制读取速率(每秒IO)从一个设备(默认[])
--device-write-bps list Limit write rate (bytes per second) to a device (default [])
将写速率(每秒字节数)限制为一个设备(默认[])
--device-write-iops list Limit write rate (IO per second) to a device (default [])
将写速率(IO /秒)限制在一个设备上(默认[])
--disable-content-trust Skip image verification (default true)
跳过镜像验证(默认为真)
--dns list Set custom DNS servers
设置自定义DNS服务器
--dns-option list Set DNS options
设置DNS选项
--dns-search list Set custom DNS search domains
设置自定义DNS搜索域
--domainname string Container NIS domain name
容器NIS域名
--entrypoint string Overwrite the default ENTRYPOINT of the image
覆盖图像的默认入口点
-e, --env list Set environment variables
设置环境变量
--env-file list Read in a file of environment variables
读取环境变量文件
--expose list Expose a port or a range of ports
公开端口或端口范围
--gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs)
将GPU设备添加到容器中('all'传递所有GPU)
--group-add list Add additional groups to join
添加其他组加入
--health-cmd string Command to run to check health
命令运行以检查健康状况
--health-interval duration Time between running the check (ms|s|m|h) (default 0s)
检查间隔时间(ms|s|m|h)(默认0秒)
--health-retries int Consecutive failures needed to report unhealthy
需要报告不健康的连续故障
--health-start-period duration Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s)
开始健康-重试倒计时前容器初始化的开始时间(ms|s|m|h)(默认0s)
--health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s)
允许一个检查运行的最长时间(ms|s|m|h)(默认0秒)
--help Print usage
打印使用信息
-h, --hostname string Container host name
容器主机名
--init Run an init inside the container that forwards signals and reaps processes
在转发信号和接收进程的容器中运行init
-i, --interactive Keep STDIN open even if not attached
保持STDIN打开,即使没有连接
--ip string IPv4 address (e.g., 172.30.100.104)
IPv4地址(例如,172.30.100.104)
--ip6 string IPv6 address (e.g., 2001:db8::33)
IPv6地址(例如,2001:db8::33)
--ipc string IPC mode to use
使用IPC模式
--isolation string Container isolation technology
容器隔离技术
--kernel-memory bytes Kernel memory limit
内核内存限制
-l, --label list Set meta data on a container
在容器上设置元数据
--label-file list Read in a line delimited file of labels
读取以行分隔的标签文件
--link list Add link to another container
添加链接到另一个容器
--link-local-ip list Container IPv4/IPv6 link-local addresses
容器IPv4/IPv6链路本地地址
--log-driver string Logging driver for the container
容器的日志驱动程序
--log-opt list Log driver options
日志驱动器选项
--mac-address string Container MAC address (e.g., 92:d0:c6:0a:29:33)
容器MAC地址(例如:92:d0:c6:0a:29:33)
-m, --memory bytes Memory limit
内存限制
--memory-reservation bytes Memory soft limit
内存软限制
--memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap
交换限制等于内存加交换:'-1'以启用无限交换
--memory-swappiness int Tune container memory swappiness (0 to 100) (default -1)
调整容器内存swappiness(0到100)(默认-1)
--mount mount Attach a filesystem mount to the container
将文件系统挂载附加到容器
--name string Assign a name to the container
为容器分配一个名称
--network network Connect a container to a network
将容器连接到网络
--network-alias list Add network-scoped alias for the container
为容器添加网络范围的别名
--no-healthcheck Disable any container-specified HEALTHCHECK
禁用任何容器指定的健康检查
--oom-kill-disable Disable OOM Killer
禁用OOM杀手
--oom-score-adj int Tune host's OOM preferences (-1000 to 1000)
调整主机的OOM首选项(-1000到1000)
--pid string PID namespace to use
要使用的PID名称空间
--pids-limit int Tune container pids limit (set -1 for unlimited)
调整容器pid限制(将-1设置为无限制)
--privileged Give extended privileges to this container
将扩展权限授予此容器
-p, --publish list Publish a container's port(s) to the host
将容器的端口发布到主机
-P, --publish-all Publish all exposed ports to random ports
将所有公开的端口发布到随机端口
--read-only Mount the container's root filesystem as read only
将容器的根文件系统挂载为只读
--restart string Restart policy to apply when a container exits (default "no")
在容器退出时应用重启策略(默认为“no”)
--rm Automatically remove the container when it exits
在容器退出时自动删除它
--runtime string Runtime to use for this container
用于此容器的运行时
--security-opt list Security Options
安全选项
--shm-size bytes Size of /dev/shm
/dev/shm大小
--sig-proxy Proxy received signals to the process (default true)
接收到进程的信号(默认为true)
--stop-signal string Signal to stop a container (default "SIGTERM")
停止容器的信号(默认为“SIGTERM”)
--stop-timeout int Timeout (in seconds) to stop a container
超时(以秒为单位)来停止容器
--storage-opt list Storage driver options for the container
容器的存储驱动程序选项
--sysctl map Sysctl options (default map[])
Sysctl选项(默认映射[])
--tmpfs list Mount a tmpfs directory
挂载tmpfs目录
-t, --tty Allocate a pseudo-TTY
分配一个pseudo-TTY
--ulimit ulimit Ulimit options (default [])
Ulimit选项(默认[])
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
用户名或 UID (格式: <name|uid>[:<group|gid>])
--userns string User namespace to use
要使用的用户名称空间
--uts string UTS namespace to use
要使用的UTS名称空间
-v, --volume list Bind mount a volume
绑定装入卷
--volume-driver string Optional volume driver for the container
容器的可选卷驱动程序
--volumes-from list Mount volumes from the specified container(s)
从指定容器装入卷
-w, --workdir string Working directory inside the container
容器内的工作目录
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[root@Server ~]# docker image ls -a
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               1.17                e791337790a6        19 hours ago        127MB
debian              10.3                378ca4b1d2fe        2 days ago          114MB
ubuntu              19.10               e9ccb229a23d        4 weeks ago         72.9MB
centos              8.1.1911            470671670cac        3 months ago        237MB
centos              7.7.1908            08d05d1d5859        5 months ago        204MB
# 以交互方式运行本地不存在的镜像创建容器,随机生成名称
[root@Server ~]# docker container run -it ubuntu:20.04 /bin/bash
Unable to find image 'ubuntu:20.04' locally
20.04: Pulling from library/ubuntu
767fb6cc1b89: Pull complete
c917d9c558a3: Pull complete
6fef7dab6264: Pull complete
bd7950fd118d: Pull complete
Digest: sha256:1515a62dc73021e2e7666a31e878ef3b4daddc500c3d031b35130ac05067abc0
Status: Downloaded newer image for ubuntu:20.04
root@ba3d978e17b0:/#
# 通过exit退出或直接关闭命令行终端之后,容器都会自动停止运行,如果需要让容器在后台运行,按住Ctrl,再按p后松开,再按q即可退出容器的命令行终端但容器并没有停止运行。
root@ba3d978e17b0:/# exit
exit
[root@Server ~]# docker image ls -a
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               1.17                e791337790a6        19 hours ago        127MB
debian              10.3                378ca4b1d2fe        2 days ago          114MB
ubuntu              20.04               a3282b72a167        4 weeks ago         73.8MB
ubuntu              19.10               e9ccb229a23d        4 weeks ago         72.9MB
centos              8.1.1911            470671670cac        3 months ago        237MB
centos              7.7.1908            08d05d1d5859        5 months ago        204MB
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS                      PORTS               NAMES
ba3d978e17b0        ubuntu:20.04        "/bin/bash"         About a minute ago   Exited (0) 36 seconds ago                       quizzical_elbakyan
# 以守护方式运行本地已存在的镜像创建容器,并命名为“nginx01”
[root@Server ~]# docker container run -d --name "nginx01" nginx:1.17
c0e4d14fe4165e403168a102892bc9863ae4bd772c3abd77be46c1530847d220
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   21 seconds ago      Up 19 seconds              80/tcp              nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              4 minutes ago       Exited (0) 3 minutes ago                       quizzical_elbakyan
3.3、查看容器命令

描述(英文):List containers
描述(中文):容器列表
语法:docker container ls [OPTIONS]
别名: ls, ps, list
选项:

选项 英文说明&中文说明
-a, --all Show all containers (default shows just running)
显示所有容器(默认显示正在运行)
-f, --filter filter Filter output based on conditions provided
根据提供的条件过滤输出
--format string Pretty-print containers using a Go template
使用Go模板打印漂亮的容器
-n, --last int Show n last created containers (includes all states) (default -1)
显示最后创建的n个容器(包括所有状态)(默认-1)
-l, --latest Show the latest created container (includes all states)
显示最新创建的容器(包括所有状态)
--no-trunc Don't truncate output
不截断输出
-q, --quiet Only display numeric IDs
只显示数字id
-s, --size Display total file sizes
显示总文件大小
[root@Server ~]# docker container ls
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"         13 seconds ago      Up 10 seconds                           reverent_almeida
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              37 seconds ago      Up 34 seconds                                   reverent_almeida
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   29 minutes ago      Exited (0) 19 minutes ago                       nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              33 minutes ago      Exited (0) 32 minutes ago                       quizzical_elbakyan
[root@Server ~]# docker container ls -a -q
1a54a9c9d8f1
c0e4d14fe416
ba3d978e17b0
[root@Server ~]# docker container ls -a --no-trunc
CONTAINER ID                                                       IMAGE               COMMAND                    CREATED              STATUS                      PORTS               NAMES
1a54a9c9d8f175be91c837e4b03df01ac36e595a15982c59318255073d3e0e8c   centos:8.1.1911     "/bin/bash"                About a minute ago   Up About a minute                               reverent_almeida
c0e4d14fe4165e403168a102892bc9863ae4bd772c3abd77be46c1530847d220   nginx:1.17          "nginx -g 'daemon off;'"   30 minutes ago       Exited (0) 20 minutes ago                       nginx01
ba3d978e17b09e99ed4d037ad3629df8683a5afdf82035d4defb5db5050502f3   ubuntu:20.04        "/bin/bash"                34 minutes ago       Exited (0) 32 minutes ago                       quizzical_elbakyan
3.4、查看容器的详细信息

描述(英文):Display detailed information on one or more containers
描述(中文):在一个或多个容器上显示详细信息
语法:docker container inspect [OPTIONS] CONTAINER [CONTAINER...]
选项:

选项 英文说明&中文说明
-f, --format string Format the output using the given Go template
使用给定的Go模板格式化输出
-s, --size Display total file sizes
显示总文件大小
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              2 minutes ago       Up 2 minutes                                    reverent_almeida
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   31 minutes ago      Exited (0) 22 minutes ago                       nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              35 minutes ago      Exited (0) 34 minutes ago                       quizzical_elbakyan
[root@Server ~]# docker container inspect nginx01
[
    {
        "Id": "c0e4d14fe4165e403168a102892bc9863ae4bd772c3abd77be46c1530847d220",
        "Created": "2020-04-18T06:48:16.08712178Z",
        "Path": "nginx",
        "Args": [
            "-g",
            "daemon off;"
        ],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2020-04-18T06:48:17.638255551Z",
            "FinishedAt": "2020-04-18T06:57:29.098589644Z"
        },
        "Image": "sha256:e791337790a6181d5ce870b3bb16de1a4d5aa3a916e8fba6907f57eb409934cf",
        "ResolvConfPath": "/var/lib/docker/containers/c0e4d14fe4165e403168a102892bc9863ae4bd772c3abd77be46c1530847d220/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/c0e4d14fe4165e403168a102892bc9863ae4bd772c3abd77be46c1530847d220/hostname",
        "HostsPath": "/var/lib/docker/containers/c0e4d14fe4165e403168a102892bc9863ae4bd772c3abd77be46c1530847d220/hosts",
        "LogPath": "/var/lib/docker/containers/c0e4d14fe4165e403168a102892bc9863ae4bd772c3abd77be46c1530847d220/c0e4d14fe4165e403168a102892bc9863ae4bd772c3abd77be46c1530847d220-json.log",
        "Name": "/nginx01",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Capabilities": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/10b36b54aaa2ef6e22867d9a2c379fa431872ec9fc8e2e94448551739500cc7c-init/diff:/var/lib/docker/overlay2/27551bbc04b30288da397ecc6d03d50b8994efe0f367763ba4119934f8c8b5c8/diff:/var/lib/docker/overlay2/2dfc45d26e8c467c10ce65d6601ba0bfa1a27b348f2a5d0c70ee75fd6483441e/diff:/var/lib/docker/overlay2/741e184f8bfb3a977cc5b5bd2ea4eaa2e30c72e4f63b7b531fd7556db2cb3d93/diff",
                "MergedDir": "/var/lib/docker/overlay2/10b36b54aaa2ef6e22867d9a2c379fa431872ec9fc8e2e94448551739500cc7c/merged",
                "UpperDir": "/var/lib/docker/overlay2/10b36b54aaa2ef6e22867d9a2c379fa431872ec9fc8e2e94448551739500cc7c/diff",
                "WorkDir": "/var/lib/docker/overlay2/10b36b54aaa2ef6e22867d9a2c379fa431872ec9fc8e2e94448551739500cc7c/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "c0e4d14fe416",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NGINX_VERSION=1.17.10",
                "NJS_VERSION=0.3.9",
                "PKG_RELEASE=1~buster"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "Image": "nginx:1.17",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            },
            "StopSignal": "SIGTERM"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "f85abcd4981b1586389602978ae58f439232f1b39a5aa8f50cd69f231a099381",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/f85abcd4981b",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "1a43a1cd3c2960498fab206a632e0953bfe7dd9cbfd96b778279b1fc12928e83",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]
3.5、查看容器的运行状态

描述(英文):Display a live stream of container(s) resource usage statistics
描述(中文):显示容器资源使用统计信息的实时流
语法:docker container stats [OPTIONS] [CONTAINER...]
选项:

选项 英文说明&中文说明
-a, --all Show all containers (default shows just running)
显示所有容器(默认显示正在运行)
--format string Pretty-print images using a Go template
使用Go模板打印漂亮的镜像
--no-stream Disable streaming stats and only pull the first result
禁用流统计,只提取第一个结果
--no-trunc Do not truncate output
不截断输出
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              14 minutes ago      Up 13 minutes                                   reverent_almeida
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   42 minutes ago      Up About a minute           80/tcp              nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              46 minutes ago      Exited (0) 45 minutes ago                       quizzical_elbakyan
[root@Server ~]# docker container stats nginx01
CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
c0e4d14fe416        nginx01             0.00%               1.941MiB / 1.943GiB   0.10%               2.41kB / 0B         8.19kB / 0B         2
3.6、查看容器的日志

描述(英文):Fetch the logs of a container
描述(中文):获取容器的日志
语法:docker container logs [OPTIONS] CONTAINER
选项:

选项 英文说明&中文说明
--details Show extra details provided to logs
显示提供给日志的额外细节
-f, --follow Follow log output
跟踪日志输出
--since string Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
显示时间戳以来的日志(如2013-01-02T13:23:37)或相关日志(如42m, 42分钟)
--tail string Number of lines to show from the end of the logs (default "all")
从日志结束处显示的行数(默认为“all”)
-t, --timestamps Show timestamps
显示时间戳
--until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
在时间戳前显示日志(如2013-01-02T13:23:37)或相关日志(如42分钟内显示42m)
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                      PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   About a minute ago   Up 59 seconds               0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              20 minutes ago       Up 20 minutes                                    reverent_almeida
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   48 minutes ago       Up 7 minutes                80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              53 minutes ago       Exited (0) 51 minutes ago                        quizzical_elbakyan
[root@Server ~]#
[root@Server ~]# docker container logs nginx02
192.168.28.42 - - [18/Apr/2020:07:36:24 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
2020/04/18 07:36:24 [error] 6#6: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.28.42, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.28.8", referrer: "http://192.168.28.8/"
192.168.28.42 - - [18/Apr/2020:07:36:24 +0000] "GET /favicon.ico HTTP/1.1" 404 556 "http://192.168.28.8/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
192.168.28.42 - - [18/Apr/2020:07:36:28 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
192.168.28.42 - - [18/Apr/2020:07:36:28 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
192.168.28.42 - - [18/Apr/2020:07:36:28 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
192.168.28.42 - - [18/Apr/2020:07:36:28 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
192.168.28.42 - - [18/Apr/2020:07:36:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
192.168.28.42 - - [18/Apr/2020:07:36:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
192.168.28.42 - - [18/Apr/2020:07:36:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
192.168.28.42 - - [18/Apr/2020:07:36:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
192.168.28.42 - - [18/Apr/2020:07:36:30 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
[root@Server ~]# docker container logs -t nginx02
2020-04-18T07:36:24.449449324Z 192.168.28.42 - - [18/Apr/2020:07:36:24 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
2020-04-18T07:36:24.818452491Z 2020/04/18 07:36:24 [error] 6#6: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 192.168.28.42, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "192.168.28.8", referrer: "http://192.168.28.8/"
2020-04-18T07:36:24.818516815Z 192.168.28.42 - - [18/Apr/2020:07:36:24 +0000] "GET /favicon.ico HTTP/1.1" 404 556 "http://192.168.28.8/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
2020-04-18T07:36:28.422103059Z 192.168.28.42 - - [18/Apr/2020:07:36:28 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
2020-04-18T07:36:28.618167612Z 192.168.28.42 - - [18/Apr/2020:07:36:28 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
2020-04-18T07:36:28.780958287Z 192.168.28.42 - - [18/Apr/2020:07:36:28 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
2020-04-18T07:36:28.954704932Z 192.168.28.42 - - [18/Apr/2020:07:36:28 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
2020-04-18T07:36:29.162934218Z 192.168.28.42 - - [18/Apr/2020:07:36:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
2020-04-18T07:36:29.397415706Z 192.168.28.42 - - [18/Apr/2020:07:36:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
2020-04-18T07:36:29.613629453Z 192.168.28.42 - - [18/Apr/2020:07:36:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
2020-04-18T07:36:29.832024323Z 192.168.28.42 - - [18/Apr/2020:07:36:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
2020-04-18T07:36:30.047095274Z 192.168.28.42 - - [18/Apr/2020:07:36:30 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.9 Safari/537.36" "-"
3.7、修改容器的名字

描述(英文):Rename a container
描述(中文):重命名容器
语法:docker container rename CONTAINER NEW_NAME

[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   4 minutes ago       Up 4 minutes                0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              23 minutes ago      Up 23 minutes                                    reverent_almeida
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   51 minutes ago      Up 10 minutes               80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              56 minutes ago      Exited (0) 54 minutes ago                        quizzical_elbakyan
[root@Server ~]# docker container rename ba3d978e17b0 ubuntu01
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   4 minutes ago       Up 4 minutes                0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              23 minutes ago      Up 23 minutes                                    reverent_almeida
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   52 minutes ago      Up 11 minutes               80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              56 minutes ago      Exited (0) 55 minutes ago                        ubuntu01
3.8、进入容器命令(attach)

描述(英文):Attach local standard input, output, and error streams to a running container
描述(中文):将本地标准输入、输出和错误流附加到正在运行的容器中
语法:docker container attach [OPTIONS] CONTAINER
选项:

选项 英文说明&中文说明
--detach-keys string Override the key sequence for detaching a container
覆盖用于分离容器的键序列
--no-stdin Do not attach STDIN
不附加标准输入
--sig-proxy Proxy all received signals to the process (default true)
代理所有接收到的进程信号(默认为true)
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   11 minutes ago      Up 10 minutes       0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              30 minutes ago      Up 30 minutes                            reverent_almeida
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   58 minutes ago      Up 17 minutes       80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              About an hour ago   Up 2 seconds                             ubuntu01
[root@Server ~]# docker container attach ubuntu01
root@ba3d978e17b0:/#
# 通过exit退出容器的终端命令行后,容器会自动停止
root@ba3d978e17b0:/# exit
exit
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   13 minutes ago      Up 13 minutes               0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              32 minutes ago      Up 32 minutes                                    reverent_almeida
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   About an hour ago   Up 20 minutes               80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              About an hour ago   Exited (0) 45 seconds ago                        ubuntu01
3.9、进入容器命令(exec)

描述(英文):Run a command in a running container
描述(中文):在正在运行的容器中运行命令
语法:docker container exec [OPTIONS] CONTAINER COMMAND [ARG...]
选项:

选项 英文说明&中文说明
-d, --detach Detached mode: run command in the background
分离模式:在后台运行命令
--detach-keys string Override the key sequence for detaching a container
覆盖用于分离容器的键序列
-e, --env list Set environment variables
设置环境变量
-i, --interactive Keep STDIN open even if not attached
保持STDIN打开,即使没有连接
--privileged Give extended privileges to the command
将扩展的特权授予该命令
-t, --tty Allocate a pseudo-TTY
分配一个pseudo-TTY
-u, --user string Username or UID (format: <name|uid>[:<group|gid>])
用户名或 UID (格式: <name|uid>[:<group|gid>])
-w, --workdir string Working directory inside the container
容器内的工作目录
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   18 minutes ago      Up 18 minutes       0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              37 minutes ago      Up 37 minutes                            centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   About an hour ago   Up 25 minutes       80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              About an hour ago   Up About a minute                        ubuntu01
[root@Server ~]# docker container exec -it centos01 /bin/bash
[root@1a54a9c9d8f1 /]#
# 通过exit退出容器的终端命令行后,容器不会自动停止
[root@1a54a9c9d8f1 /]# exit
exit
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   19 minutes ago      Up 19 minutes       0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              39 minutes ago      Up 39 minutes                            centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   About an hour ago   Up 26 minutes       80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              About an hour ago   Up 2 minutes                             ubuntu01
3.10、复制文件

描述(英文):Copy files/folders between a container and the local filesystem
描述(中文):在容器和本地文件系统之间复制文件/文件夹
语法:docker container cp [OPTIONS] CONTAINER:SRC_PATH | -
    docker cp [OPTIONS] SRC_PATH | - CONTAINER:DEST_PATH
说明(英文):Use '-' as the source to read a tar archive from stdin and extract it to a directory destination in a container.
        Use '-' as the destination to stream a tar archive of a container source to stdout.
说明(中文):使用'-'作为从stdin读取tar存档的源,并将其解压缩到容器中的目录目的地。
        使用“-”作为目标,将容器源的tar存档流传输到stdout。
选项:

选项 英文说明&中文说明
-a, --archive Archive mode (copy all uid/gid information)
存档模式(复制所有uid/gid信息)
-L, --follow-link Always follow symbol link in SRC_PATH
始终遵循SRC_PATH中的符号链接
3.11、查看容器内被修改的文件

描述(英文):Inspect changes to files or directories on a container's filesystem
描述(中文):检查容器文件系统中文件或目录的更改
语法:docker container diff CONTAINER

[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   33 minutes ago      Up 33 minutes       0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              52 minutes ago      Up 52 minutes                            centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   About an hour ago   Up 40 minutes       80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              About an hour ago   Up 16 minutes                            ubuntu01
[root@Server ~]# docker container diff nginx01
C /var
C /var/cache
C /var/cache/nginx
A /var/cache/nginx/scgi_temp
A /var/cache/nginx/uwsgi_temp
A /var/cache/nginx/client_temp
A /var/cache/nginx/fastcgi_temp
A /var/cache/nginx/proxy_temp
C /run
A /run/nginx.pid
3.12、停止容器

描述(英文):Stop one or more running containers
描述(中文):停止一个或多个运行的容器
语法:docker container stop [OPTIONS] CONTAINER [CONTAINER...]
选项:

选项 英文说明&中文说明
-t, --time int Seconds to wait for stop before killing it (default 10)
等待停止的秒数(默认10)
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   36 minutes ago      Up 36 minutes       0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              56 minutes ago      Up 56 minutes                            centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   About an hour ago   Up 43 minutes       80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              About an hour ago   Up 19 minutes                            ubuntu01
# 停止一个容器
[root@Server ~]# docker container stop nginx01
nginx01
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   37 minutes ago      Up 37 minutes              0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              56 minutes ago      Up 56 minutes                                   centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   About an hour ago   Exited (0) 2 seconds ago                        nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              About an hour ago   Up 19 minutes                                   ubuntu01
# 停止所有的容器
# docker container stop $(docker container ls -a -q)
[root@Server ~]# docker container stop `docker container ls -a -q`
56b589309afd
1a54a9c9d8f1
c0e4d14fe416
ba3d978e17b0
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                          PORTS               NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   38 minutes ago      Exited (0) 4 seconds ago                            nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              58 minutes ago      Exited (0) 4 seconds ago                            centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   About an hour ago   Exited (0) About a minute ago                       nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              2 hours ago         Exited (0) 4 seconds ago                            ubuntu01
3.13、启动容器

描述(英文):Start one or more stopped containers
描述(中文):启动一个或多个停止的容器
语法:docker container start [OPTIONS] CONTAINER [CONTAINER...]
选项:

选项 英文说明&中文说明
-a, --attach Attach STDOUT/STDERR and forward signals
连接STDOUT/STDERR和转发信号
--detach-keys string Override the key sequence for detaching a container
覆盖用于分离容器的键序列
-i, --interactive Attach container's STDIN
将容器的STDIN
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   42 minutes ago      Exited (0) 3 minutes ago                       nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              About an hour ago   Exited (0) 3 minutes ago                       centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   2 hours ago         Exited (0) 5 minutes ago                       nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              2 hours ago         Exited (0) 3 minutes ago                       ubuntu01
# 启动一个容器
[root@Server ~]# docker container start centos01
centos01
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   42 minutes ago      Exited (0) 3 minutes ago                       nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              About an hour ago   Up 2 seconds                                   centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   2 hours ago         Exited (0) 5 minutes ago                       nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              2 hours ago         Exited (0) 3 minutes ago                       ubuntu01
# 启动所有容器
# docker container start `docker container ls -a -q`
[root@Server ~]# docker container start $(docker container ls -a -q)
56b589309afd
1a54a9c9d8f1
c0e4d14fe416
ba3d978e17b0
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   43 minutes ago      Up 9 seconds        0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              About an hour ago   Up 34 seconds                            centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   2 hours ago         Up 7 seconds        80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              2 hours ago         Up 6 seconds                             ubuntu01
3.14、删除容器

描述(英文):Remove one or more containers
描述(中文):移除一个或多个容器
语法:docker container rm [OPTIONS] CONTAINER [CONTAINER...]
选项:

选项 英文说明&中文说明
-f, --force Force the removal of a running container (uses SIGKILL)
强制移除正在运行的容器(使用SIGKILL)
-l, --link Remove the specified link
删除指定的链接
-v, --volumes Remove anonymous volumes associated with the container
删除与容器关联的匿名卷
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   48 minutes ago      Up 5 minutes        0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              About an hour ago   Up 5 minutes                             centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   2 hours ago         Up 5 minutes        80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              2 hours ago         Up 5 minutes                             ubuntu01
[root@Server ~]# docker container rm ubuntu01
Error response from daemon: You cannot remove a running container ba3d978e17b09e99ed4d037ad3629df8683a5afdf82035d4defb5db5050502f3. Stop the container before attempting removal or force remove
[root@Server ~]# docker container stop ubuntu01
ubuntu01
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   49 minutes ago      Up 6 minutes                0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              About an hour ago   Up 7 minutes                                     centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   2 hours ago         Up 6 minutes                80/tcp               nginx01
ba3d978e17b0        ubuntu:20.04        "/bin/bash"              2 hours ago         Exited (0) 15 seconds ago                        ubuntu01
# 删除一个容器
[root@Server ~]# docker container rm ubuntu01
ubuntu01
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
56b589309afd        nginx:1.17          "nginx -g 'daemon of…"   50 minutes ago      Up 7 minutes        0.0.0.0:80->80/tcp   nginx02
1a54a9c9d8f1        centos:8.1.1911     "/bin/bash"              About an hour ago   Up 7 minutes                             centos01
c0e4d14fe416        nginx:1.17          "nginx -g 'daemon of…"   2 hours ago         Up 7 minutes        80/tcp               nginx01
# 强制删除所有的容器
# docker container rm -f $(docker container ls -a -q)
[root@Server ~]# docker container rm -f `docker container ls -a -q`
56b589309afd
1a54a9c9d8f1
c0e4d14fe416
[root@Server ~]# docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,921评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,635评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,393评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,836评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,833评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,685评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,043评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,694评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,671评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,670评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,779评论 1 332
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,424评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,027评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,984评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,214评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,108评论 2 351
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,517评论 2 343

推荐阅读更多精彩内容