在docker-compose中将docker容器的生成名称传递给另一个容器 [英] Passing a docker container's generated name to another container in docker-compose
问题描述
生成Docker-compose中的容器名称。我需要将此名称传递给另一个容器,以便连接。
我的方案是,我想创建一个基于docker容器的容器,并与主持人,在同胞容器中执行一些事情,作为其中的第二个进程。
那么我如何在另一个容器中有一个容器的名称?
没有办法传递容器名称。您最好的选择是使用 COMPOSE_PROJECT_NAME
设置项目名称,并使用环境将其传递到容器中: - COMPOSE_PROJECT_NAME =
。
然后,您可以使用< project name> _< service name> _1
来预测容器名称。 / p>
另一个选项是从 docker-compose events
中拖尾事件流。这应该提供您需要的所有信息。
Container names, in docker-compose, are generated. And I need to pass this name to another container so it can make a connection.
My scenario is, I want to create a container based on docker's container and communicating with the host, execute some thing in a sibling container as the second process within it.
So how can I have a container's name within another?
There is no way to pass the container name. Your best option is to set a project name with COMPOSE_PROJECT_NAME
, and pass that into the container with environment: - COMPOSE_PROJECT_NAME=
.
Then you can predict the container name using <project name>_<service name>_1
.
Another option is to tail the event stream from docker-compose events
. That should provide all the information you need.
这篇关于在docker-compose中将docker容器的生成名称传递给另一个容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!