I trying to create network in docker-compose.vs.debug.yml file:
networks: myNetwork: driver: bridge
But docker adding some identifier:
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.
If you want to add a container to a network after the container is already running, use the docker network connect subcommand. You can connect multiple containers to the same network. Once connected, the containers can communicate using only another container's IP address or name.
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
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.
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
and make it something different that you prefer, then you can predict the network name created from it.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With