How to run docker containers in their network with an external gateway?

David

I have some images that I'm managing with docker-compose and I need to run them in a different network than that of the host machine (which is running Ubuntu 16).

Host machine has IP 10.0.1.19/24 and gateway 10.0.1.1.

This is my docker-compose.yml:

version: '2'
services:
  db:
    ...
    networks:
      ab-net:
        ipv4_address: 10.1.2.250
    ...

  app:
    ...
    networks:
      ab-net:
        ipv4_address: 10.1.2.11
    ...

networks:
  ab-net:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 10.1.2.0/23
          gateway: 10.1.2.1

The firewall (which is out of my control and can't be changed) allows direct incoming connections to 10.1.2.0/23 via containers' gateway 10.1.2.1 (which is the firewall itself) and not to the host.

Running the container with that configuration, docker configures a br-interface on the host with IP 10.1.2.1; thus on the network there are two machines with the same IP: the host and the firewall/gateway.

Containers have access to the internet, they see each others and from the host machine I can connect to the containers.

How can I have that scenario working? At this stage I would prefer not to use any orchestration tool, if possible.

David

I found out that the only option to do that is using the (currently) experimental feature "Ipvlan Network".

The Linux implementations are extremely lightweight because rather than using the traditional Linux bridge for isolation, they are simply associated to a Linux Ethernet interface or sub-interface to enforce separation between networks and connectivity to the physical network.

The documentation is quite large and can't be copied here, however those are the commands I had to run to achieve that:

echo 8021q >> /etc/modules
modprobe 8021q
apt-get install vlan
edit /etc/network/interfaces

auto eth1.2320
iface eth1.2320 inet manual
    vlan-raw-device eth1

auto eth1.2321
iface eth1.2321 inet manual
    vlan-raw-device eth1

auto eth1.2322
iface eth1.2322 inet manual
    vlan-raw-device eth1

auto eth1.2323
iface eth1.2323 inet manual
    vlan-raw-device eth1

auto eth1.2324
iface eth1.2324 inet manual
    vlan-raw-device eth1

/etc/init.d/networking restart

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to run a cron job inside a docker container?

分類Dev

How to assign domain names to containers in Docker?

分類Dev

How to run 2 commands with docker exec

分類Dev

How to list containers in Docker

分類Dev

How to run external process in Scala and get both exit code and output?

分類Dev

AWS API Gateway with external authentication

分類Dev

How to run symfony via docker-composer

分類Dev

How to use local docker containers with Kubernetes

分類Dev

How to run Tensorboard and jupyter concurrently with docker?

分類Dev

What does it mean that `docker run --network=container:CONTAINERID`?

分類Dev

Traefik > "Bad gateway" (error 502) for some containers

分類Dev

How does docker network work?

分類Dev

Django how to run external module as Daemon

分類Dev

How to run an external library into different nodes?[MPI]

分類Dev

how to start postgres prior to run docker

分類Dev

Docker and Gitlab - how to modify the docker run

分類Dev

How to add a docker container to an existing docker network

分類Dev

Building Docker Containers in VSTS

分類Dev

How to schedule a docker run on google cloud

分類Dev

How to access service running docker with network_mode: "host" from external IP

分類Dev

How to cleanup docker containers and images on linux machines

分類Dev

How can I run Thanos on Docker?

分類Dev

how to actually install mediawiki and run with docker?

分類Dev

How to run command on connect to network

分類Dev

Docker Not Linking Containers

分類Dev

Linking Docker Containers

分類Dev

Log management of various docker containers

分類Dev

How to get Shared file system for docker containers running on different hosts?

分類Dev

How would one specify which containers to start and not to start in docker-compose? (docker run vs docker create)

Related 関連記事

  1. 1

    How to run a cron job inside a docker container?

  2. 2

    How to assign domain names to containers in Docker?

  3. 3

    How to run 2 commands with docker exec

  4. 4

    How to list containers in Docker

  5. 5

    How to run external process in Scala and get both exit code and output?

  6. 6

    AWS API Gateway with external authentication

  7. 7

    How to run symfony via docker-composer

  8. 8

    How to use local docker containers with Kubernetes

  9. 9

    How to run Tensorboard and jupyter concurrently with docker?

  10. 10

    What does it mean that `docker run --network=container:CONTAINERID`?

  11. 11

    Traefik > "Bad gateway" (error 502) for some containers

  12. 12

    How does docker network work?

  13. 13

    Django how to run external module as Daemon

  14. 14

    How to run an external library into different nodes?[MPI]

  15. 15

    how to start postgres prior to run docker

  16. 16

    Docker and Gitlab - how to modify the docker run

  17. 17

    How to add a docker container to an existing docker network

  18. 18

    Building Docker Containers in VSTS

  19. 19

    How to schedule a docker run on google cloud

  20. 20

    How to access service running docker with network_mode: "host" from external IP

  21. 21

    How to cleanup docker containers and images on linux machines

  22. 22

    How can I run Thanos on Docker?

  23. 23

    how to actually install mediawiki and run with docker?

  24. 24

    How to run command on connect to network

  25. 25

    Docker Not Linking Containers

  26. 26

    Linking Docker Containers

  27. 27

    Log management of various docker containers

  28. 28

    How to get Shared file system for docker containers running on different hosts?

  29. 29

    How would one specify which containers to start and not to start in docker-compose? (docker run vs docker create)

ホットタグ

アーカイブ