4

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 ?

Nisse Engström
  • 208
  • 2
  • 5
KodeFor.Me
  • 209
  • 3
  • 5
  • 14
  • Fix the *real* problem -- the "error related to the network" -- or use different IP ranges for different networks. You can't use the same IP ranges for different networks on the same machine. – womble Dec 20 '17 at 02:21
  • @womble thank you for your reply. Can you please become more specific? I am totally new on Docker and I don't understand all you describe. – KodeFor.Me Dec 20 '17 at 07:17
  • I've been as specific as I can be with the information provided. I can't tell you how to fix an "error related to the network" without knowing what that error is, and if you need more specific than "use different IP ranges for different networks" and "You can't use the same IP ranges for different networks on the same machine.", then I really don't know what to say. – womble Dec 20 '17 at 23:55

3 Answers3

7

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.

Lena Weber
  • 303
  • 1
  • 4
5

List all network

$ip a

If you see the bridge with br-a675c47764eb and its status is down,delete it

$brctl delbr br-a675c47764eb

Then restart docker

$service docker restart

Run docker-compose Again

Jenny D
  • 27,358
  • 21
  • 74
  • 110
michael
  • 51
  • 1
  • 1
1

If you run it on linux system, just confirm that your iptables has opened the port that your docker-compose need. Like this:

iptables -I INPUT -p tcp --dport 80 -s 0.0.0.0 -j ACCEPT

# or

vim /etc/sysconfig/iptables

# then

systemctl restart iptables

Then remove the conflict network on the same subnet:

docker network ls

docker network rm <id>

If above cant work, just restart docker, it should be all right.

EdenSheng
  • 11
  • 2