获取容器列表
docker container ls [OPTIONS] or docker ps [OPTIONS] Options: -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 -n, --last int Show n last created containers (includes all states) (default -1) -l, --latest Show the latest created container (includes all states) --no-trunc Don't truncate output -q, --quiet Only display container IDs -s, --size Display total file sizes不加任何参数情况下,列出正在运行的容器:
docker container ls or docker ps 两种命令效果一样 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 8efed1c23ff5 4b "catalina.sh run" 6 minutes ago Up 6 minutes 0.0.0.0:8088->8080/tcp, :::8088->8080/tcp charming_pike增加-a参数,可以查看所有的容器。
dokcer ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 30c33d778412 4b "catalina.sh run" 20 seconds ago Up 17 seconds 0.0.0.0:8089->8080/tcp, :::8089->8080/tcp elated_northcutt 8efed1c23ff5 4b "catalina.sh run" 7 minutes ago Exited (143) 3 seconds ago charming_pike pause暂停一个或多个容器
docker container pause CONTAINER [CONTAINER...] or docker pause CONTAINER [CONTAINER...]查看容器运行情况
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 30c33d778412 4b "catalina.sh run" 5 minutes ago Up 5 minutes 0.0.0.0:8089->8080/tcp, :::8089->8080/tcp elated_northcutt 8efed1c23ff5 4b "catalina.sh run" 12 minutes ago Up 6 seconds 0.0.0.0:8088->8080/tcp, :::8088->8080/tcp charming_pike暂停上面列出来的容器
docker pause 30c33d778412 8efed1c23ff5 暂停成功输出容器ID 30c33d778412 8efed1c23ff5查看所有容器
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 30c33d778412 4b "catalina.sh run" 6 minutes ago Up 6 minutes (Paused) 0.0.0.0:8089->8080/tcp, :::8089->8080/tcp elated_northcutt 8efed1c23ff5 4b "catalina.sh run" 13 minutes ago Up About a minute (Paused) 0.0.0.0:8088->8080/tcp, :::8088->8080/tcp charming_pike从结果的STATUS列可以看到,后面多了(Paused),表示容器已经暂停。
unpause取消一个或多个暂停的容器
docker container unpause CONTAINER [CONTAINER...] or docker unpause CONTAINER [CONTAINER...]上面我们已经暂停了两个容器,现在使用unpause取消暂停
docker unpause 30c33d778412 8efed1c23ff5 30c33d778412 8efed1c23ff5使用ps -a命令查看
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 30c33d778412 4b "catalina.sh run" 9 minutes ago Up 9 minutes 0.0.0.0:8089->8080/tcp, :::8089->8080/tcp elated_northcutt 8efed1c23ff5 4b "catalina.sh run" 17 minutes ago Up 4 minutes 0.0.0.0:8088->8080/tcp, :::8088->8080/tcp charming_pike port列出容器的端口映射或特定映射
docker container port CONTAINER [PRIVATE_PORT[/PROTO]] or docker port CONTAINER [PRIVATE_PORT[/PROTO]]查看容器端口映射
docker container port 30c33d778412 8080/tcp -> 0.0.0.0:8089 8080/tcp -> :::8089 prune