docker ps -s
时间: 2024-01-29 10:10:42 浏览: 177
`docker ps -s`命令用于列出所有正在运行的容器,并显示它们的文件大小。下面是一个示例:
```shell
$ docker ps -s
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE
e7a5d3e8a6f1 nginx:latest "nginx -g 'daemon of…" 2 hours ago Up 2 hours 80/tcp webserver 2.5MB (virtual 2.5MB)
```
上面的输出中,`SIZE`列显示了容器的文件大小。在这个例子中,容器的文件大小为2.5MB。
相关问题
docker ps -a
This command is used to list all containers, including stopped ones. It displays information such as the container ID, image used to create the container, command run in the container, status, creation time, and ports exposed.
Example output:
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b4c6fbd5b17 nginx:latest "/docker-entrypoint.…" 2 hours ago Exited (0) 2 hours ago elegant_mendeleev
f1cdd5b5a4cf postgres:latest "docker-entrypoint.s…" 4 days ago Exited (0) 4 days ago pensive_hoover
c2b2d9a9cfeb redis:latest "docker-entrypoint.s…" 2 weeks ago Exited (137) 2 weeks ago nostalgic_poincare
```
#!/bin/bash# 检查 Docker 是否已安装if ! command -v docker &> /dev/nullthen echo "Docker 未安装" echo "请先安装 Docker" echo "参考命令:" echo "curl -fsSL https://get.docker.com -o get-docker.sh" echo "sudo sh get-docker.sh" exitfi# 检查 docker-compose 是否已安装if ! command -v docker-compose &> /dev/nullthen echo "docker-compose 未安装" echo "请先安装 docker-compose" echo "参考命令:" echo "sudo curl -L \"https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)\" -o /usr/local/bin/docker-compose" echo "sudo chmod +x /usr/local/bin/docker-compose" exitfi# 进入项目所在目录cd /home/flow/deploy/deploy-online/project-docker# 使用 docker-compose 命令创建镜像docker-compose build# 启动容器docker-compose up -d# 检查容器是否启动成功if [ "$(docker ps -q -f name=my_container)" ]then echo "容器已启动"else echo "容器启动失败"fi
这是一个bash脚本,用于检查Docker和docker-compose是否已安装,并在项目目录下使用docker-compose构建和启动容器。如果容器成功启动,则输出“容器已启动”,否则输出“容器启动失败”。
您可以将此脚本保存为一个文件,例如“deploy.sh”,然后在终端中使用以下命令运行:
```
bash deploy.sh
```
注意,您需要将脚本中的项目目录、容器名称以及docker-compose版本等参数替换为您自己的实际情况。
阅读全文