Docker Compose - 向网络名称添加标识符 [英] Docker Compose - adding identifier to network name
问题描述
我试图在 docker-compose.vs.debug.yml 文件中创建网络:
I trying to create network in docker-compose.vs.debug.yml file:
networks:
myNetwork:
driver: bridge
但是 docker 添加了一些标识符:
But docker adding some identifier:
docker 网络 ls ->
docker network ls ->
NETWORK ID NAME DRIVER SCOPE
0e1fec1a9a30 dockercompose1163770330_myNetwork bridge local
如果有任何选项可以这样命名:
If there any option to name it like this:
NETWORK ID NAME DRIVER SCOPE
0e1fec1a9a30 myNetwork bridge local
我需要它自动连接不同项目中的两个容器.
I need it to connect automatically two containers on separate projects.
推荐答案
如果你让 docker-compose 创建网络,它会自行决定名称.通常,它会查看 docker-compose.yml 所在目录的名称,并将其用作前缀.根据您显示的名称,此 docker-compose.yml 文件似乎位于名为 dockercompose1163770330
的目录中.它将它与您指定的 myNetwork
名称结合起来,并创建一个名为 dockercompose1163770330_myNetwork
的网络.
If you have docker-compose create the network, it will determine the name itself. Normally, it looks at the name of the directory where docker-compose.yml is located, and uses that as a prefix. Based on the name you have shown, it appears that this docker-compose.yml file is in a directory named dockercompose1163770330
. It combines this with the myNetwork
name you specified, and creates a network named dockercompose1163770330_myNetwork
.
如果您想控制网络的确切名称,您有两个选择.
If you want to control the exact name of the network, you have two options.
- 使用在 docker-compose 之外创建的网络(外部"网络).
networks:
default:
external:
name: myNetwork
这意味着其他东西已经创建了网络.如果您还没有这样的网络,创建它很容易.
This implies something else has created the network already. If you don't have such a network already, creating it is easy.
docker network create myNetwork
- (如果可能)确定视觉工作室如何命名它的路径,并将该路径更改为静态路径.这是否可能,或者如何,我不知道.但是,如果您可以控制
dockercompose1163770330
并使其成为您喜欢的不同内容,那么您就可以预测由此创建的网络名称.
- (If possible) determine how visual-studio names it paths, and change that path to something static. Whether this is possible, or how, I have no idea. But if you can control
dockercompose1163770330
and make it something different that you prefer, then you can predict the network name created from it.
这篇关于Docker Compose - 向网络名称添加标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!