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
根據(jù)容器的更改創(chuàng)建新映像
cp Copy files/folders between a container and the local filesystem
在容器和本地文件系統(tǒng)之間復(fù)制文件/文件夾
create Create a new container
創(chuàng)建一個新容器
diff Inspect changes to files or directories on a container's filesystem
檢查容器文件系統(tǒng)中文件或目錄的更改
exec Run a command in a running container
在正在運行的容器中運行命令
export Export a container's filesystem as a tar archive
將容器的文件系統(tǒng)導(dǎo)出為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
顯示容器資源使用統(tǒng)計信息的實時流
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躏率、創(chuàng)建容器命令

描述(英文):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(相對權(quán)重)民鼓,在10和1000之間薇芝,或0禁用(默認0)
--blkio-weight-device list Block IO weight (relative device weight) (default [])
塊IO權(quán)值(相對設(shè)備權(quán)值)(默認[])
--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(完全公平調(diào)度程序)周期
--cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
限制CPU CFS(完全公平調(diào)度程序)配額
--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份額(相對權(quán)重)
--cpus decimal Number of CPUs
CPU的數(shù)量
--cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
允許執(zhí)行的CPU (0- 3,0,1)
--cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
允許執(zhí)行的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
將主機設(shè)備添加到容器中
--device-cgroup-rule list Add a rule to the cgroup allowed devices list
在cgroup允許設(shè)備列表中添加一個規(guī)則
--device-read-bps list Limit read rate (bytes per second) from a device (default [])
限制從設(shè)備讀取速率(每秒字節(jié)數(shù))(默認[])
--device-read-iops list Limit read rate (IO per second) from a device (default [])
限制讀取速率(每秒IO)從一個設(shè)備(默認[])
--device-write-bps list Limit write rate (bytes per second) to a device (default [])
將寫速率(每秒字節(jié)數(shù))限制為一個設(shè)備(默認[])
--device-write-iops list Limit write rate (IO per second) to a device (default [])
將寫速率(IO /秒)限制在一個設(shè)備上(默認[])
--disable-content-trust Skip image verification (default true)
跳過鏡像驗證(默認為真)
--dns list Set custom DNS servers
設(shè)置自定義DNS服務(wù)器
--dns-option list Set DNS options
設(shè)置DNS選項
--dns-search list Set custom DNS search domains
設(shè)置自定義DNS搜索域
--domainname string Container NIS domain name
容器NIS域名
--entrypoint string Overwrite the default ENTRYPOINT of the image
覆蓋圖像的默認入口點
-e, --env list Set environment variables
設(shè)置環(huán)境變量
--env-file list Read in a file of environment variables
讀取環(huán)境變量文件
--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設(shè)備添加到容器中('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
需要報告不健康的連續(xù)故障
--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
在轉(zhuǎn)發(fā)信號和接收進程的容器中運行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
容器隔離技術(shù)
--kernel-memory bytes Kernel memory limit
內(nèi)核內(nèi)存限制
-l, --label list Set meta data on a container
在容器上設(shè)置元數(shù)據(jù)
--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
容器的日志驅(qū)動程序
--log-opt list Log driver options
日志驅(qū)動器選項
--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
內(nèi)存限制
--memory-reservation bytes Memory soft limit
內(nèi)存軟限制
--memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap
交換限制等于內(nèi)存加交換:'-1'以啟用無限交換
--memory-swappiness int Tune container memory swappiness (0 to 100) (default -1)
調(diào)整容器內(nèi)存swappiness(0到100)(默認-1)
--mount mount Attach a filesystem mount to the container
將文件系統(tǒng)掛載附加到容器
--name string Assign a name to the container
為容器分配一個名稱
--network network Connect a container to a network
將容器連接到網(wǎng)絡(luò)
--network-alias list Add network-scoped alias for the container
為容器添加網(wǎng)絡(luò)范圍的別名
--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)
調(diào)整主機的OOM首選項(-1000到1000)
--pid string PID namespace to use
要使用的PID名稱空間
--pids-limit int Tune container pids limit (set -1 for unlimited)
調(diào)整容器pid限制(將-1設(shè)置為無限制)
--privileged Give extended privileges to this container
將擴展權(quán)限授予此容器
-p, --publish list Publish a container's port(s) to the host
將容器的端口發(fā)布到主機
-P, --publish-all Publish all exposed ports to random ports
將所有公開的端口發(fā)布到隨機端口
--read-only Mount the container's root filesystem as read only
將容器的根文件系統(tǒng)掛載為只讀
--restart string Restart policy to apply when a container exits (default "no")
在容器退出時應(yīng)用重啟策略(默認為“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
容器的存儲驅(qū)動程序選項
--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
容器的可選卷驅(qū)動程序
--volumes-from list Mount volumes from the specified container(s)
從指定容器裝入卷
-w, --workdir string Working directory inside the container
容器內(nèi)的工作目錄
[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
# 以交互方式運行本地不存在的鏡像創(chuàng)建容器,隨機生成名稱
[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退出或直接關(guān)閉命令行終端之后饮亏,容器都會自動停止運行耍贾,如果需要讓容器在后臺運行,按住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
# 以守護方式運行本地已存在的鏡像創(chuàng)建容器简肴,并命名為“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
根據(jù)提供的條件過濾輸出
--format string Pretty-print containers using a Go template
使用Go模板打印漂亮的容器
-n, --last int Show n last created containers (includes all states) (default -1)
顯示最后創(chuàng)建的n個容器(包括所有狀態(tài))(默認-1)
-l, --latest Show the latest created container (includes all states)
顯示最新創(chuàng)建的容器(包括所有狀態(tài))
--no-trunc Don't truncate output
不截斷輸出
-q, --quiet Only display numeric IDs
只顯示數(shù)字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、查看容器的運行狀態(tài)

描述(英文):Display a live stream of container(s) resource usage statistics
描述(中文):顯示容器資源使用統(tǒng)計信息的實時流
語法: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
禁用流統(tǒng)計能扒,只提取第一個結(jié)果
--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
顯示提供給日志的額外細節(jié)
-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)或相關(guān)日志(如42m, 42分鐘)
--tail string Number of lines to show from the end of the logs (default "all")
從日志結(jié)束處顯示的行數(shù)(默認為“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)或相關(guān)日志(如42分鐘內(nèi)顯示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
設(shè)置環(huán)境變量
-i, --interactive Keep STDIN open even if not attached
保持STDIN打開频蛔,即使沒有連接
--privileged Give extended privileges to the command
將擴展的特權(quán)授予該命令
-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
容器內(nèi)的工作目錄
[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秦叛、復(fù)制文件

描述(英文):Copy files/folders between a container and the local filesystem
描述(中文):在容器和本地文件系統(tǒng)之間復(fù)制文件/文件夾
語法: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存檔流傳輸?shù)絪tdout三圆。
選項:

選項 英文說明&中文說明
-a, --archive Archive mode (copy all uid/gid information)
存檔模式(復(fù)制所有uid/gid信息)
-L, --follow-link Always follow symbol link in SRC_PATH
始終遵循SRC_PATH中的符號鏈接
3.11、查看容器內(nèi)被修改的文件

描述(英文):Inspect changes to files or directories on a container's filesystem
描述(中文):檢查容器文件系統(tǒng)中文件或目錄的更改
語法: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)
等待停止的秒數(shù)(默認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和轉(zhuǎn)發(fā)信號
--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
刪除與容器關(guān)聯(lián)的匿名卷
[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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末查库,一起剝皮案震驚了整個濱河市路媚,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌樊销,老刑警劉巖整慎,帶你破解...
    沈念sama閱讀 218,607評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異围苫,居然都是意外死亡裤园,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,239評論 3 395
  • 文/潘曉璐 我一進店門剂府,熙熙樓的掌柜王于貴愁眉苦臉地迎上來拧揽,“玉大人,你說我怎么就攤上這事腺占∮偻啵” “怎么了?”我有些...
    開封第一講書人閱讀 164,960評論 0 355
  • 文/不壞的土叔 我叫張陵衰伯,是天一觀的道長铡羡。 經(jīng)常有香客問我,道長嚎研,這世上最難降的妖魔是什么蓖墅? 我笑而不...
    開封第一講書人閱讀 58,750評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮临扮,結(jié)果婚禮上论矾,老公的妹妹穿的比我還像新娘。我一直安慰自己杆勇,他們只是感情好贪壳,可當我...
    茶點故事閱讀 67,764評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著蚜退,像睡著了一般闰靴。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上钻注,一...
    開封第一講書人閱讀 51,604評論 1 305
  • 那天蚂且,我揣著相機與錄音,去河邊找鬼幅恋。 笑死杏死,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的捆交。 我是一名探鬼主播淑翼,決...
    沈念sama閱讀 40,347評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼品追!你這毒婦竟也來了玄括?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,253評論 0 276
  • 序言:老撾萬榮一對情侶失蹤肉瓦,失蹤者是張志新(化名)和其女友劉穎遭京,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體泞莉,經(jīng)...
    沈念sama閱讀 45,702評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡洁墙,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,893評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了戒财。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片热监。...
    茶點故事閱讀 40,015評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖饮寞,靈堂內(nèi)的尸體忽然破棺而出孝扛,到底是詐尸還是另有隱情,我是刑警寧澤幽崩,帶...
    沈念sama閱讀 35,734評論 5 346
  • 正文 年R本政府宣布苦始,位于F島的核電站,受9級特大地震影響慌申,放射性物質(zhì)發(fā)生泄漏陌选。R本人自食惡果不足惜理郑,卻給世界環(huán)境...
    茶點故事閱讀 41,352評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望咨油。 院中可真熱鬧您炉,春花似錦、人聲如沸役电。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,934評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽法瑟。三九已至冀膝,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間霎挟,已是汗流浹背窝剖。 一陣腳步聲響...
    開封第一講書人閱讀 33,052評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留酥夭,地道東北人枯芬。 一個月前我還...
    沈念sama閱讀 48,216評論 3 371
  • 正文 我出身青樓,卻偏偏與公主長得像采郎,于是被迫代替她去往敵國和親千所。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,969評論 2 355

推薦閱讀更多精彩內(nèi)容