[英]How to show all running containers created by docker-compose, globally, regardless of docker-compose.yml
I have several docker-compose.yml
files, running ok with docker-compose up
, individually.我有几个
docker-compose.yml
文件,分别运行docker-compose up
正常。
Each docker-compose runs several containers.每个 docker-compose 运行多个容器。
After they are up, I can't see what containers are up with docker ps
.在它们启动后,我看不到
docker ps
有哪些容器。
I can see something with docker-compose ps
, but only for a specific docker-compose.yml.我可以看到
docker-compose ps
的一些东西,但仅限于特定的 docker-compose.yml。
I want access to global polling of the containers state.我想访问容器 state 的全局轮询。
How can I list all running containers, no matter their origin?如何列出所有正在运行的容器,无论其来源如何?
Here is kind of a guess based on the clues of your question.这是根据您的问题的线索进行的猜测。
When you do run containers via docker-compose up
, please do mind that hitting CTRL+C will actually stop your containers.当您通过
docker-compose up
运行容器时,请注意按CTRL+C实际上会停止您的容器。
Here is an example of doing this:这是执行此操作的示例:
$ docker-compose up
[+] Running 1/0
⠿ Container docker-test-1 Created 0.0s
Attaching to docker-test-1
^CGracefully stopping... (press Ctrl+C again to force)
[+] Running 1/1
⠿ Container docker-test-1 Stopped 10.2s
canceled
The important part here being: ^CGracefully stopping...
这里的重要部分是:
^CGracefully stopping...
If you want to keep them running, you will have to run docker-compose up
in a detached mode, with the help of the -d
option.如果你想让它们继续运行,你必须在
-d
选项的帮助下以分离模式运行docker-compose up
。
-d, --detach Detached mode: Run containers in the background, print new container names. Incompatible with --abort-on-container-exit.
Source: https://docs.docker.com/compose/reference/up/资料来源: https://docs.docker.com/compose/reference/up/
So doing,这样做,
docker-compose up -d && docker ps
Should actually give you what you expected.实际上应该给你你所期望的。
Eg:例如:
$ docker-compose up -d && docker ps
[+] Running 2/2
⠿ Network docker_default Created 0.1s
⠿ Container docker-test-1 Started 0.5s
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ab9f422247c9 alpine "tail -f /dev/null" 1 second ago Up Less than a second docker-test-1
And if you want to see all container, regardless of their state, you can use the -a
option of docker ps
.如果你想查看所有容器,不管它们的 state,你可以使用
docker ps
的-a
选项。
--all, -a Show all containers (default shows just running)
Source: https://docs.docker.com/engine/reference/commandline/ps/资料来源: https://docs.docker.com/engine/reference/commandline/ps/
Eg:例如:
$ docker-compose up
[+] Running 2/2
⠿ Network docker_default Created 0.1s
⠿ Container docker-test-1 Created 0.1s
Attaching to docker-test-1
^CGracefully stopping... (press Ctrl+C again to force)
[+] Running 1/1
⠿ Container docker-test-1 Stopped 10.2s
canceled
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
615bcc6f1e50 alpine "tail -f /dev/null" 18 seconds ago Exited (137) 3 seconds ago docker-test-1
Docker compose adds labels to each container that it creates. Docker compose 将标签添加到它创建的每个容器。 If you want to get all containers created by compose, you can perform a container ls and apply a filter.
如果要获取 compose 创建的所有容器,可以执行容器 ls 并应用过滤器。
docker container ls --filter label=com.docker.compose.project
This will show all running container created by compose, regardless of the project name.这将显示由 compose 创建的所有正在运行的容器,无论项目名称如何。
For example, I created 2 apps in 2 different compose projects.例如,我在 2 个不同的撰写项目中创建了 2 个应用程序。 loadbalancer and manager .
负载均衡器和管理器。 With the command, I get both back, but no other container that have not been created by compose and therefore don't container a project label.
使用该命令,我将两者都返回,但没有其他尚未由 compose 创建的容器,因此不包含项目 label。
$ docker container ls --filter label=com.docker.compose.project --format \
'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Label "com.docker.compose.project"}}\t{{.Networks}}'
CONTAINER ID NAMES STATUS project NETWORKS
791f4059b4af loadbalancer_app_1 Up 11 minutes loadbalancer loadbalancer_default
8d26e4503721 manager_app_1 Up 24 minutes manager manager_default
To list all running containers in docker列出 docker 中所有正在运行的容器
$docker ps
$码头工人ps
When containers are running and are created as a part of docker definition present in docker-compose.yml files.当容器正在运行并作为 docker-compose.yml 文件中存在的 docker 定义的一部分创建时。 In a basic scenario, i would do
在基本情况下,我会做
$docker-compose up -d
$docker-compose up -d
to start the container and use the below command to check the containers are running启动容器并使用以下命令检查容器是否正在运行
$ docker-compose ps
$ docker-compose ps
First command should contain the results from the compose command as well.第一个命令也应该包含来自 compose 命令的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.