Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to join the default bridge network with docker-compose v2?

I tried to setup an nginx-proxy container to access my other containers via subdomains on port 80 instead of special ports. As you can guess, I could not get it to work.

I'm kind of new to docker itself and found that it's more comfortable for me to write docker-compose.yml files so I don't have to constantly write long docker run ... commands. I thought there's no difference in how you start the containers, either with docker or docker-compose. However, one difference I noticed is that starting the container with docker does not create any new networks, but with docker-compose there will be a xxx_default network afterwards.

I read that containers on different networks cannot access each other and maybe that might be the reason why the nginx-proxy is not forwarding the requests to the other containers. However, I was unable to find a way to configure my docker-compose.yml file to not create any new networks, but instead join the default bridge network like docker run does.

I tried the following, but it resulted in an error saying that I cannot join system networks like this:

networks:   default:     external:       name: bridge 

I also tried network_mode: bridge, but that didn't seem to make any difference.

How do I have to write the docker-compose.yml file to not create a new network, or is that not possible at all?

Bonus question: Are there any other differences between docker and docker-compose that I should know of?

like image 787
noone Avatar asked May 03 '17 07:05

noone


People also ask

What is the default network in Docker compose?

Pre-Existing Networks In this case, Docker Compose never creates the default network; instead connecting the app's containers to the i-already-created-this network.

Does Docker compose create a bridge network?

Docker Compose understands the idea behind running services for one application on one network. When you deploy an app using Docker Compose file, even when there's no mention of specific networking parameters, Docker Compose will create a new bridge network and deploy the container over that network.

What is default bridge network in Docker?

When you start Docker, a default bridge network (also called bridge ) is created automatically, and newly-started containers connect to it unless otherwise specified. You can also create user-defined custom bridge networks. User-defined bridge networks are superior to the default bridge network.


1 Answers

Adding network_mode: bridge to each service in your docker-compose.yml will stop compose from creating a network.

If any service is not configured with this bridge (or host), a network will be created.

Tested and confirmed with:

version: "2.1"  services:   app:     image: ubuntu:latest     network_mode: bridge 
like image 149
Rawkode Avatar answered Sep 20 '22 05:09

Rawkode