Docker Compose - adding identifier to network name

后端 未结 3 2199
猫巷女王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:12

    Per https://docs.docker.com/compose/networking/:

    Networks can also be given a custom name (since version 3.5):

    version: "3.5"
    networks:
      frontend:
        name: custom_frontend
        driver: custom-driver-1
    

    So you could choose to simply name your network myNetwork like this:

    networks:
      myNetwork:
        name: myNetwork
        driver: bridge
    

    Alternatively, if you want your container to join an existing network (I know you say you want docker-compose to create the network for you, but for people reading this question this might be helpful), https://docs.docker.com/compose/networking/ states:

    If you want your containers to join a pre-existing network, use the external option:

    networks:
      default:
        external:
          name: my-pre-existing-network
    

提交回复
热议问题