"docker ps"和"docker container ls"有什么区别吗?

110
docker psdocker container ls的文档都写着“列出容器”,但没有提到另一个命令。这两个命令有什么区别吗?输出结果看起来完全一样:
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                    NAMES
bbe3d7158eaa        flaskmysqldockerized_web   "python app.py"          5 hours ago         Up 18 seconds       0.0.0.0:8082->5000/tcp   flaskmysqldockerized_web_1
4f7d3f0763ad        mysql                      "docker-entrypoint..."   6 hours ago         Up 18 seconds       0.0.0.0:3307->3306/tcp   flaskmysqldockerized_db_1
3个回答

131

docker psdocker container ls之间没有区别。在Docker 1.13中添加了新的命令结构(docker container <subcommand>),以提供更结构化的用户体验。

据我所知,尚未有任何官方公告放弃对旧式命令(如docker ps和其他命令)的支持,尽管可以合理地假设这可能会在将来的某个时候发生。

这在发布Docker 1.13版本的博客文章中有描述。

Docker has grown many features over the past couple years and the Docker CLI now has a lot of commands (40 at the time of writing). Some, like build or run are used a lot, some are more obscure, like pause or history. The many top-level commands clutters help pages and makes tab-completion harder.

In Docker 1.13, we regrouped every command to sit under the logical object it’s interacting with. For example list and startof containers are now subcommands of docker container and history is a subcommand of docker image.

docker container list
docker container start
docker image history

These changes let us clean up the Docker CLI syntax, improve help text and make Docker simpler to use. The old command syntax is still supported, but we encourage everybody to adopt the new syntax.


1
博客文章的更新链接:https://www.docker.com/blog/whats-new-in-docker-1-13/ - Eirik Lid

33

docker ps是“docker process status”的简写,而docker container ls是更冗长的docker container list的简写。

正如被接受的答案所解释的那样,它们的工作方式没有任何区别,docker container ls是“新的”命令,因此您应该优先使用它。

实际上,这两个命令默认只显示正在运行的容器,这使得第一个命令(docker ps)有点困惑,因为单独运行该命令并不真正显示“进程状态”。要查看所有容器的状态,请添加“-a”选项表示“全部”(或使用“--all”),例如:

docker container ls -a

较旧的命令

docker ps -adocker container ps -a


-1
没有区别,至少对于Docker版本24.0.2来说。
如果你运行以下命令:
docker container ls -h

你会得到一本手册,上面写着 'docker ps' 是 'docker container ls' 的别名: docker container ls -h

这个有什么额外的内容,与https://dev59.com/z1cO5IYBdhLWcg3wxEYP#45254760相比? - Martin Thoma

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接