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?
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.
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.
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.
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
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