“ docker ps”和“ docker Container ls”有区别吗?

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
20505 次浏览

There is no difference between docker ps and docker container ls. The new command structure (docker container <subcommand>) was added in Docker 1.13 to provider a more structured user experience when using the command line.

To my knowledge, there has not yet been any official announcement to drop support for the old-style commands (like docker ps and others), although it might be reasonable to assume this might happen at some point in the future.

This is described in a blog post accompanying the release of 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.

docker ps is shorthand that stands for "docker process status", whilst docker container ls is shorthand for the more verbose docker container list.

As the accepted answer explains, there is no difference in how they work, and docker container ls is the 'newer' command, so you should probably prefer it.

Both commands actually only show running containers by default, which makes the first one (docker ps) a little more confusing as that command on its own isn't really showing 'process status'. To see the status of all containers, add the -a option for 'all' (or use --all), e.g.

docker container ls -a

older

docker ps -a or docker container ps -a