可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
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 Update, 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.
回答2:
To list all running and stopped containers
docker ps -a
To list all running containers (just stating the obvious and also example use of -f filtering option)
docker ps -a -f status=running
To list all running and stopped containers, showing only their container id
docker ps -aq
To remove all containers that are NOT running
docker rm `docker ps -aq -f status=exited`
回答3:
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.
回答4:
docker ps -s will show the size of running containers only.
To check the size of all containers use docker ps -as
回答5:
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)
回答6:
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.
回答7:
I got the error message Cannot connect to the Docker daemon.
I forgot I am running the daemon as root and needed sudo
:
$ sudo docker ps
回答8:
docker ps [OPTIONS]
Following command will show only running containers by default.
docker ps
To see all containers:
docker ps -a
For showing the latest created container:
docker ps -l