I have an environment which consist of 3 application, 2 running in Windows and 1 running in Debian OS.
For testing purpose, I already build the environment in only 1 PC (running Windows 10) with VirtualBox VM (for running Debian OS).
Below is detail network configuration:
Host PC (using 2 VirtualBox Host Only Adapter):
Ethernet adapter VirtualBox Host-Only Network:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::ec0c:3c16:4f85:1a5e%12
IPv4 Address. . . . . . . . . . . : 192.168.1.11
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.12
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.13
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.14
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.15
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.21
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.22
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.23
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.24
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.25
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.26
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.31
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.32
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.33
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.34
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.123
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Ethernet adapter VirtualBox Host-Only Network #2:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::5d7:813f:a9a:865d%16
IPv4 Address. . . . . . . . . . . : 192.168.1.122
Subnet Mask . . . . . . . . . . . : 255.255.255.248
Default Gateway . . . . . . . . . :
VirtualBox VM network configuration:
/etc/network/interfaces:
auto lo
iface lo inet loopback
auto eth1
iface eth1 inet static
address 192.168.1.120
netmask 255.255.255.0
gateway 192.168.1.1
auto eth2
allow-hotplug eth2
iface eth2 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
auto eth2:0
iface eth2:0 inet static
address 192.168.1.20
netmask 255.255.255.0
auto eth2:1
iface eth2:1 inet static
address 192.168.1.30
netmask 255.255.255.0
Ifconfig output:
eth0 Link encap:Ethernet HWaddr 08:00:27:a8:08:8b
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
...
eth1 Link encap:Ethernet HWaddr 08:00:27:41:27:73
inet addr:192.168.1.120 Bcast:192.168.1.255 Mask:255.255.255.0
...
eth2 Link encap:Ethernet HWaddr 08:00:27:0d:6b:54
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
...
eth2:0 Link encap:Ethernet HWaddr 08:00:27:0d:6b:54
inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
...
eth2:1 Link encap:Ethernet HWaddr 08:00:27:0d:6b:54
inet addr:192.168.1.30 Bcast:192.168.1.255 Mask:255.255.255.0
...
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
...
Below is some flow of network interaction in current environment:
The environment is working OK now, but after read about Docker, I plan to replace VirtualBox VM with using Docker for reduce memory usage.
I successed build up an Debian image, setup library, etc...
However, I don't know how to setup network in Docker for having similar function with above VirtualBox VM configuration. Some dificult points:
To make a port available to services outside of Docker, or to Docker containers which are not connected to the container's network, use the --publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host to the outside world.
You can create multiple networks with Docker and add containers to one or more networks. Containers can communicate within networks but not across networks. A container with attachments to multiple networks can connect with all of the containers on all of those networks.
Manage a user-defined bridge Use the docker network create command to create a user-defined bridge network. You can specify the subnet, the IP address range, the gateway, and other options. See the docker network create reference or the output of docker network create --help for details.
The first three questions you asked are solved with macvlan
network. You'll have containers directly attached to your network, just like VM's. Here's an example:
version: "2.1"
services:
nginx1:
image: nginx
networks:
network_1:
ipv4_address: 10.1.1.115
nginx2:
image: nginx
networks:
network_1:
ipv4_address: 10.1.1.116
networks:
network_1:
driver: macvlan
driver_opts:
parent: enp52s0 # Your network interface name
ipam:
driver: default
config:
- subnet: 10.1.1.0/24
gateway: 10.1.1.1
In this example I declared a macvlan network named network_1
, which attached to the enp52s0
network interface. The two nginx
containers use that network and each advertises its own static IP.
Now if you want to assign more than one IP per container things begin to get messy. To assign an additional address you need an additional network, with its own IP range, its own parent network interface, and its own gateway. That is literally another network. Or you can think of some hack, maybe using a proxy container that'll listen on another IP and forward traffic into desired container but it's kinda 'meh'. I'd say that VM overhead does not worth all that trouble unless you are open to redesign connectivity of your application.
In the docker documentation there are articles about "user defined" network bridges, the link can be found here. I think you'll have to create those according to your network architecture and once they are made then you can specify when creating a docker container that it should use one of the user-defined bridges that you created.
As you are using multiple applications and would like to put this in multiple docker containers I would also suggest to look into "docker-compose". With this you can create a YML manifest that will spin up multiple docker containers with their defined configs, networks, specific ports, ... all at once so you can launch/shutdown the whole environment at once.
An example and even more information on ip addresses of docker images can be found in this article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With