Docker Community Forums

Share and learn in the Docker community.

Docker container visible on 2 publics ip same time

hi

i got 2 internets provider, i got 2 network card eth0 and eth1

here my gateway ISP ip

192.168.1.1 provider 1
192.168.0.1 provider 2

How on docker-compose to use the 2 providers on the same time for my containers ?

For now only provider 1 is use by docker container

here my config for version 2

networks:
   websites:
    ipam:
      config:
        - subnet: 172.20.0.0/16
          ip_range: 172.28.5.0/24

Regards

I thought there are experts on this forum…

It is up to you to present your case - you choose to present it with least amount of details and it didn’t catch attention. Even experts are no magicians.

How to got both internet providers working at same time on my docker container ?

In my docker container, i want to have 2 ethernet card. Each card is configured to one internet provider.

best regards

If it’s about incomming ingress communication (and it’s responses): a published port will always bind the port on 0.0.0.0, thus both interfaces are already used.

It it’s about outgoing egress communication: Docker will always use the defined default gateway of the host .This problem needs to be solved on the host level, not on the container level.

i got a website configured inside this docker, need to be alive even if one provider if down.

Where to find documentation for this case ?

Like I already wrote, by default a published port binds to 0.0.0.0 which are ALL interfaces. This does not contradict with your requirement, does it?

You must be right but it is not working for me; here my full config docker-compose.yml

version: '2'

services:
    db:
        container_name: Percona-Mysql
        image: percona
        restart: always
        volumes:
            - "./mysql:/var/lib/mysql"
        environment:
            MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
            MYSQL_USER: ${MYSQL_USER}
            MYSQL_DATABASE: ${MYSQL_DATABASE}
        networks:
          websites:
            ipv4_address: 172.20.0.2

    php:
        container_name: Php
        restart: always
        build:
            context: php7-fpm
            args:
                TIMEZONE: ${TIMEZONE}
        volumes:
            - ./www:/var/www
        networks:
          websites:
            ipv4_address: 172.20.0.3

    nginx:
        container_name: Nginx
        restart: always
        build: nginx
        volumes_from:
            - php
        volumes:
            - ./logs/nginx/:/var/log/nginx
        ports:
            - 80:80
            - 8089:8089
            - 443:443
        networks:
          websites:
            ipv4_address: 172.20.0.5
         
    phpmyadmin:
        container_name: Phpmyadmin
        restart: always
        image: phpmyadmin/phpmyadmin
        ports:
            - 8090:80
        networks:
          websites:
            ipv4_address: 172.20.0.4

    redis:
        container_name: Redis
        image: redis
        ports:
          - "6379:6379"
        volumes:
          - ./redis:/data
        restart: always
        networks:
          websites:
            ipv4_address: 172.20.0.6


networks:
   websites:
    ipam:
      config:
        - subnet: 172.20.0.0/16
          ip_range: 172.28.5.0/24

I have specific port for nginx, when provider 1 is down, provider 2 not working, no internet inside the container

Hint: default gateway (on the host)

You are still trying to solve the problem at the wong place. This is not a docker problem.

ok, thank you for your response

There are a lot of variables you are not accounting for.

First answer the following questions:
Are you using two different ISPs or the same one with dual links?
Why are you trying to use two different ISPs? Redundancy, performance, etc?
Are you just directly assigning public IPs to the two interfaces on the docker host?
What other networking gear do you have?
How are you defining your DNS entries?

Off the top of my head, the real professional/enterprise solution for this is as follows:
1 - Purchase your own public IP space (min is /24 I believe)
2 - Get two ISPs that will advertise your space and will peer with you (normally done with BGP)
3 - Purchase a router and/or a firewall (a real router/firewall not a best buy one; example Cisco or Palo Alto) that will large enough to learn all the internet routes from your ISP
4 - Peer with both ISPs and advertise your public IP address space out both ISPs at the same time
5 - Assign your docker host with a single public IP or NAT the internal address to one of your public IPs
6 - You are done!

The result of this will be the following:
1 - Users that are closer on the internet (not physically closer) will route through the closer ISP. Just because your DC is next door to Starbucks, doesn’t mean Starbucks is closer on the internet than the McDonalds 2 miles away. This happens due everyone having different ISPs. Those ISPs have to peer together and sometimes that peering point is in a different state/country.
2 - If one of your ISP links goes down, all traffic will automatically flow in and out the other. When it comes back up, it will automatically go back out both.
3 - You will be load balancing between the two ISPs depending on where your users are sourcing

I work as an network engineer and this is what I do on a daily basis. Granted I may have missed some finer points, no one is perfect. This solution is not cheap and you may be better off looking for a cloud hosting provider. Based on what you are trying to host / do, I would look into DigitalOcean. They take care of these things in the background so you don’t have to worry about it.

1 Like

i have 2 different ISP, to always have internet at home use, if one of them is broken.

I use unraid as OS, and use docker to deliver webserver for my personnal website, no big deal.

i am assigning static ip, gateway and dns for my 2 ethernet cards respectively for each ISP. Default gateway card 1 is IP of the modem of ISP 1, gateway card 2 is IP of modem ISP2.

If i don’t use a gateway, i don’t have internet at all.

I just have 2 modem, and 2 gigabit routers to deliver my lan network.

I use opendns dns server for both my modems.

Is it clearer now ? As for now, i didn’t solve my issue :slight_smile:

Edit: If you are using Docker-for-mac or Docker-for-Windows 18.03+, just connect to your mysql service using the host host.docker.internal (instead of the 127.0.0.1 in your connection string).

As of Docker 18.09.3, this does not work on Docker-for-Linux. A fix has been submitted on March the 8th, 2019 and will hopefully be merged to the code base. Until then, a workaround is to use a container as described