Docker Compose-为网络名称添加标识符 [英] Docker Compose - adding identifier to network name

查看:669
本文介绍了Docker Compose-为网络名称添加标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在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 network ls->

docker network ls ->

NETWORK ID          NAME                                         DRIVER              SCOPE 
0e1fec1a9a30        dockercompose1163770330_myNetwork            bridge              local

如果可以这样命名:

NETWORK ID          NAME                                         DRIVER              SCOPE
0e1fec1a9a30        myNetwork                                    bridge              local

我需要它在单独的项目上自动连接两个容器。

I need it to connect automatically two containers on separate projects.

推荐答案

如果您有docker-compose create网络,它将确定名称本身。通常,它会查看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.


  1. 使用网络在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




  1. (如果可能)确定如何以可视方式-工作室将其命名为路径,然后将该路径更改为静态。无论这是可能的,还是如何,我都不知道。但是,如果您可以控制 dockercompose1163770330 并使其与您喜欢的有所不同,则可以预测由此创建的网络名称。

  1. (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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆