I have a server on my network and I would like to use that one to pretend to be many different servers.
The physical pc is running a Ubuntu server and when connected to the network the dhcp server gives that server ip number 192.168.1.10.
Then inside of that it is fairly easy to start many different docker images and to avoid collisions on ports I can give the services non standard port numbers. However that is not very user friendly for the other users on the network.
It would be more user friendly to expose each docker image with it's own ip-number.
Let's therefore try to describe a typical usecase, where this server would host both a gitlab and a jenkins master.
This setup is possible with VirtualBox when the virtual servers uses "bridged adapters", however I'm struggling to do the same but with dockers instead. (Please note that I don't want to use VirtualBox for this since it eats so much resources compared with docker).
From my basic understading of docker, it seems like I need to create a couple of virtual docker networks, however I can't figure out if those should be "bridge", "macvlan" or similar to create this.
What I have tried are for example to create 2 bridged networks in on the host ubuntu server
First we have the default network
enp0s31f6 Link encap:Ethernet HWaddr 54:bf:64:96:51:57
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fdac:b176:f48b:0:c9bf:3d46:a9f6:8a08/64 Scope:Global
inet6 addr: fe80::6f2:9b6e:b8a4:225/64 Scope:Link
inet6 addr: fdac:b176:f48b:0:de76:744c:f42a:75e1/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1356 errors:0 dropped:0 overruns:0 frame:0
TX packets:842 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:152299 (152.2 KB) TX bytes:63753 (63.7 KB)
Interrupt:16 Memory:ef500000-ef520000
Then I find the one that docker created:
docker0 Link encap:Ethernet HWaddr 02:42:b1:ff:6e:89
inet addr:172.17.0.1 Bcast:172.17.255.255 Mask:255.255.0.0
inet6 addr: fe80::42:b1ff:feff:6e89/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4372 errors:0 dropped:0 overruns:0 frame:0
TX packets:4665 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:175876 (175.8 KB) TX bytes:333163 (333.1 KB)
And then I created bridge11 for the .11 and bridge12 for .12
bridge11 Link encap:Ethernet HWaddr 4a:2b:6b:07:51:70
inet addr:192.168.1.11 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
bridge12 Link encap:Ethernet HWaddr 82:ec:66:9c:f2:b5
inet addr:192.168.1.12 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:828 (828.0 B)
However when I try to start a vanilla gitlab docker image with the .12 network
docker run \
--name gitlab \
--hostname gitlab \
--publish 192.168.1.12:443:443 \
--publish 192.168.1.12:80:80 \
--publish 192.168.1.12:22:22 \
--volume /var/gitlab/config:/etc/gitlab:Z \
--volume /var/gitlab/logs:/var/log/gitlab:Z \
--volume /var/gitlab/data:/var/opt/gitlab:Z \
gitlab/gitlab-ce:latest
Then he complains that port 22 is already in use like this:
docker: Error response from daemon:
driver failed programming external connectivity on endpoint gitlab
(4fda91298a6b9d416cb7e91813d95ad0d35315260881377d1238887724cf3d1f):
Error starting userland proxy: listen tcp 192.168.1.12:22:
bind: address already in use.
ERRO[0000] error waiting for container: context canceled
Please note that port 22 is in use on 192.168.1.10 not on 192.168.1.12, and if I use another unused port, that actually works.
However my idea was to be able to reuse things like the standard ssh port on different docker images.