-
Notifications
You must be signed in to change notification settings - Fork 0
Docker Network
By default, Docker Compose creates a new network when you build and run an application without defining a network in the docker-compose.yml file. The default network takes on the name [directory]_default where directory is the name of the directory that contains your docker-compose.yml file. Inside it, services defined in the docker-compose.yml can communicate with each other by name rather than IP address.
Normally the creation of this network does not cause any issues, but occasionally, Docker might mistakenly assign a subnet that is being used by your server for other purposes to this default network. This overlap will break connections.
By default, the IP range for the docker0 bridge adapter is 172.17.0.0/16. When creating a new network without defining the network range yourself, Docker will then use 172.18.0.0/16, then 172.18.0.0/16 the next time, and so on. If for instance your server uses 172.19.0.0/16 to connect to some other VPC, connections to and from there will fail. (See this StackOverflow answer for more details.)
If you do not have access to network configuration files on your server, the proposed solution in the StackOverflow response above might not be possible for you to implement. Other workarounds to try:
- Get a list of network ranges your server is using for other purposes and define your Docker networks explicitly in the
docker-compose.ymlso that you don't accidentally use any of the network ranges from that list. I do this in this project (seedocker-compose.yml). - For simple applications where you don't need communication between your containers or where you only have one container, it may be much easier to just use Docker's default bridge network. Just add
network_mode: bridgeto the service definition like so:
services:
app:
image: ubuntu:latest
network_mode: bridge