problem background
There are two servers, the upstream nginx host (ip: 172.19.xx), and the downstream nginx host (172.17.xx). One day, it was found that the upstream nginx host could not communicate with the downstream nginx host. Recalling that I recently operated docker compose upping
on the downstream nginx host , After careful investigation, it was found that in addition to the docker0 network card (ip: 172.18.0.1), there is also the network card br-4f284f2c67de (ip: 172.19.0.1) created during execution, which is on the same network segment as the upstream nginx host, resulting in failure.docker compose up
analyze
According to the information, each docker-compose.yml
will create a network, and the correspondingly created container will connect to this network, so that it can communicate. Because the host machine is a network, when 172.17.x.x
docker first creates the network docker0, the network is created 172.18.x.x
. When docker compose up, Create a new network , which happens to conflict 172.19.x.x
with the server in the network segment of the LAN , so there is a network failure; the solution is to kill this network.172.19.x.x
solve
-
First, stop the container and delete the container, delete the network
executiondocker compose down
-
Secondly, solve it from the root,
docker-compose.yml
use the specified network in
version: '3'
services:
app1:
build: ./app1
networks:
- my_network
networks:
my_network:
driver: bridge
ipam:
driver: default
# 使用非局域网网段
subnet: 172.20.0.0/16
gateway: 172.20.0.1