0

Requirement:

setup of docker instances based on Ubuntu 14.04 where 1 instance acts like a gateway for network traffic to all others...

Create a docker compose file for such a setup...

All these instances need to on their own dedicated docker network and the default docker bridge...

Created a Dockerfile

FROM ubuntu:14.04

# Set environment variables.
ENV HOME /root

# Define working directory.
WORKDIR /root

# Define default command.
CMD ["/bin/bash"]

docker-compose.yml

version: '3'
services:
  main:
    image: testenginer_main
    tty: true

  first:
    image: testenginer_main
    tty: true

where testenginer_main is image file which I generated using Dockerfile setup
I checked both Instance are up and running

Issue is I want to have 2 Network 1 which connects to docker's default bridge network and 2nd connected to other containers so other containers can access main network through network 1

MyTwoCents
  • 7,284
  • 3
  • 24
  • 52

1 Answers1

1

Edit-1

If you need internet access on main network then you need to first two networks

docker network create --subnet=172.19.0.0/16 internet
docker network create --internal --subnet 10.1.1.0/24 no-internet

For above you can look at more details on

Restrict Internet Access - Docker Container

Now you can update the compose as below

version: '3'
services:
  main:
    image: testenginer_main
    tty: true
    networks:
      - internet
      - no-internet
  first:
    image: testenginer_main
    tty: true
    networks: 
      - no-internet
networks:
  no-internet:
    external: true
  internet:
    external: true

Now if you run the containers you will see main has internet access while first doesn't

$ docker-compose ps
   Name       Command    State   Ports
--------------------------------------
ub_first_1   /bin/bash   Up
ub_main_1    /bin/bash   Up

$ docker-compose exec main apt update
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
^C
$ docker-compose exec first apt update
Err:1 http://archive.ubuntu.com/ubuntu xenial InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu xenial-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
....
W: Some index files failed to download. They have been ignored, or old ones used instead.

You can even make each compose create their own network with the options

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265