大网数据广告活动
服务器运维问答

Docker Compose returns error "networks have overlapping IPv4"

· 52CE 我爱测

starting by saying I am totally new to Docker and I am not yet familiarized with the Docker ecosystem. What I try to perform is to create a docker-composer.yml to be used in my local dev environment across my projects. I already …

问题原文

原帖链接 · KodeFor.Me · CC BY-SA 3.0

starting by saying I am totally new to Docker and I am not yet familiarized with the Docker ecosystem.

What I try to perform is to create a docker-composer.yml to be used in my local dev environment across my projects.

I already use the wp-local-docker for my WordPress projects, but I also have old projects that come with different requirements and for that reason, I did my own docker-compose.yml. The code of my own docker-compose.yml is the following:

version: "3.4"
services:
   database:
      image: mysql:latest
      ports:
         - "3306:3306"
      environment:
         MYSQL_ROOT_PASSWORD: password
         MYSQL_DATABASE: appdb
         MYSQL_USER: appuser
         MYSQL_PASSWORD: password
      volumes:
         - $PWD/data/db:/var/lib/mysql
      networks:
          app_net:
              ipv4_address: 192.168.50.10
   phpmyadmin:
      image: phpmyadmin/phpmyadmin:latest
      links:
         - database:mysql
      ports:
         - "8181:80"
      environment:
         MYSQL_ROOT_PASSWORD: password
         MYSQL_USER: appuser
         MYSQL_PASSWORD: password
         PMA_HOST: mysql
         PMA_PORT: 3306
         PMA_USER: appuser
         PMA_PASSWORD: password
      networks:
         app_net:
            ipv4_address: 192.168.50.11
   web:
      build: $PWD/ApachePHP
      depends_on:
         - database
      links:
         - database:mysql
         - mailcatcher
      ports:
         - "8080:80"
         - "443:443"
      volumes:
         - $PWD/www:/var/www/html
         - $PWD/ApachePHP/000-default.conf:/etc/apache2/sites-available/000-default.conf
      environment:
         - MYSQL_ROOT_PASSWORD=appuser
         - MYSQL_ROOT_USER=password
      networks:
         app_net:
            ipv4_address: 192.168.50.12
   mailcatcher:
      image: schickling/mailcatcher
      ports:
         - "1025:1025"
         - "1080:1080"
      environment:
         MAILCATCHER_PORT: 1025
      networks:
         app_net:
            ipv4_address: 192.168.50.13
networks:
   app_net:
      driver: bridge
      ipam:
         driver: default
         config:
            - subnet: 192.168.50.0/24

The reason I have installed the network is that when I try to access the database server, I get an error related to the network.

After a long time of research, I found that when I use the volumes in database service I get back the error. If you try it, you will find that when you try to access the phpmyadmin you will get the same error.

Again, after a long time of research, I found that I can use the volumes for the database if I set up a network.

Now when I did the first run this worked like a charm. In the test folder, I had the database files in my host folder under the path /data/db

Then I stopped the docker compose using the command docker-compose stop and then I moved to another folder, in which I copied the docker-compose.yml and then I run the docker-compose up.

Unfortunately this time I got the following error:

Creating network "corfurealestatedch_app_net" with driver "bridge" ERROR: cannot create network 791b388ece09120f1138d48427969c23ded22c6fc73699b7f8c2c8e195b59586 (br-791b388ece09): conflicts with network a675c47764eba17e3338860f56512067df580cef31415906ec57fa3b64f3cdab (br-a675c47764eb): networks have overlapping IPv4

So the question is if I can set up the docker-compose.yml in a such a way that it can be used across my local projects without conflicting with the other containers IPs.

I know, of course I can have a different IP range / sub net for each project, but I am thinking that this could become a mess in a sort period of time.

Any idea on how I can fix that ?

社区高分解答

原帖链接 · Lena Weber · CC BY-SA 3.0

From the error you’ve shown here, it looks to me that docker is trying to create a network with bridge driver named br-791b388ece09, which then complains has an overlapping IP subnet with the bridge br-a675c47764eb.

So first check your available networks using:

$ docker network ls

If you see the bridge with the ID a675c47764eb, make sure this is deleted first before creating new one on the same subnet, for this use:

$ docker network rm a675c47764eb

Then rerun your docker setup for swarm, it should properly create the network.

Alternatively, you can use a different IP subnet. Replace 192.168.50.x with something like 192.168.51.x. This should solve your problem as well.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-12-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。