Docker Compose - adding identifier to network name

后端 未结 3 2198
猫巷女王i
猫巷女王i 2021-02-07 09:53

I trying to create network in docker-compose.vs.debug.yml file:

networks:
  myNetwork:
    driver: bridge

But docker adding some identifier:

3条回答
  •  借酒劲吻你
    2021-02-07 10:30

    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. Use a network created outside of docker-compose (an "external" network).
    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. (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.

提交回复
热议问题