How to list containers in Docker

2019-01-20 20:48发布

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

Other than becoming root and looking into /var/lib/docker there doesn't seem a way to do that. Am I missing something? Is that something one isn't supposed to do?

标签: docker
12条回答
We Are One
2楼-- · 2019-01-20 21:32

docker ps -s will show the size of running containers only.

To check the size of all containers use docker ps -as

查看更多
走好不送
3楼-- · 2019-01-20 21:32

To list only the containers SHA1:

docker ps -aq --no-trunc

That way, you can use the list of all containers for other commands (which accept multiple container ids as parameters).

For example, to list only the name of all containers (since docker ps list only their names with other information):

docker inspect --format='{{.Name}}' $(sudo docker ps -aq --no-trunc)
查看更多
Viruses.
4楼-- · 2019-01-20 21:32

It is always recommended to add the user in a Docker group.

That can be done like:

sudo groupadd docker
sudo usermod -aG docker $USER  --> Equivalent to this you can add the user 
                                   in /etc/passwd manually.
查看更多
Bombasti
5楼-- · 2019-01-20 21:34

There are also the following options:

docker container ls
docker container ls -a
# --all, -a
# Show all containers (default shows just running)

since: 1.13.0 (2017-01-18):

Restructure CLI commands by adding docker image and docker container commands for more consistency #26025

and as stated here: Introducing Docker 1.13, users are encouraged to adopt the new syntax:

CLI restructured

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

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.

查看更多
【Aperson】
6楼-- · 2019-01-20 21:37

Note that some time ago there was an update to this command. It will not show the container size by default (since this is rather expensive for many running containers). Use docker ps -s to display container size as well.

查看更多
时光不老,我们不散
7楼-- · 2019-01-20 21:39

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:

docker ps -n=-1

To display total file sizes use the given command:

docker ps -s

The content presented above is from docker.com.

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

docker container ls

Is used to list all the running containers.

docker container ls -a

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

Here container is the management command.

查看更多
登录 后发表回答