Is there a difference between "docker ps" and "docker container ls"?

Docker

Docker Problem Overview


The documentation of docker ps and docker container ls both says "List containers", but does not mention the other command. Is there a difference between those two commands?

The output looks exactly the same:

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

Docker Solutions


Solution 1 - Docker

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.

Solution 2 - Docker

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMartin ThomaView Question on Stackoverflow
Solution 1 - DockerhelmbertView Answer on Stackoverflow
Solution 2 - DockerChris HalcrowView Answer on Stackoverflow