Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

docker - 如何在Docker中列出容器(How to list containers in Docker)

There's a command to list images, docker images , but there doesn't seem to be a corresponding docker containers .

(有一个命令可以列出镜像, docker images ,但是似乎没有相应的docker containers 。)

Other than becoming root and looking into /var/lib/docker there doesn't seem a way to do that.

(除了成为root并查看/var/lib/docker ,似乎没有其他方法可以做到。)

Am I missing something?

(我想念什么吗?)

Is that something one isn't supposed to do?

(那是不应该做的事情吗?)

  ask by w00t translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To show only running containers use the given command:

(要仅显示正在运行的容器,请使用给定命令:)

docker ps

To show all containers use the given command:

(要显示所有容器,请使用给定命令:)

docker ps -a

To show the latest created container (includes all states) use the given command:

(要显示最新创建的容器 (包括所有状态),请使用给定命令:)

docker ps -l

To show n last created containers (includes all states) use the given command:

(要显示n个最后创建的容器 (包括所有状态),请使用给定命令:)

docker ps -n=-1

To display total file sizes use the given command:

(要显示总文件大小,请使用给定命令:)

docker ps -s

The content presented above is from docker.com .

(上面显示的内容来自docker.com 。)

In the new version of Docker, commands are updated, and some management commands are added:

(在新版本的Docker中,命令已更新,并添加了一些管理命令:)

docker container ls

It is used to list all the running containers.

(它用于列出所有正在运行的容器。)

docker container ls -a

And then, if you want to clean them all,

(然后,如果您要清洁它们,)

docker rm $(docker ps -aq)

It is used to list all the containers created irrespective of its state.

(它用于列出所有创建的容器,无论其状态如何。)

And to stop all the Docker containers (force)

(并停止所有Docker容器(强制执行))

docker rm -f $(docker ps -a -q)  

Here the container is the management command.

(这里的容器是管理命令。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...