0

My aim is that the docker container gets an IP different from server IP it is hosted on AND is reachable from VPN client

My server hosting docker config:

$ sudo docker -v
Docker version 19.03.6, build 369ce74a3c
$ sudo docker-compose -v
docker-compose version 1.17.1, build unknown
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:    18.04
Codename:   bionic

The server is connected to a network on 192.168.0.0/24 with gateway on 192.168.0.10.

And I have another server with OpenVPN with ips 192.168.0.150 and 12.20.0.1 (for VPN).

Every computer connected in remote to the VPN gets an ip on 12.20.0.0/24 network


Previously, I used an Ubuntu VM on VirtualBox and I added a route on each VM to be accessible from VPN

ip route add 12.20.0.0/24 via 192.168.0.150

This worked!


Now I'm using docker to replace my VM To get a different IP from server on 192.168.0.0/24 network I created a docker network macvlan:

sudo docker network create -d macvlan -o parent=eno1 --subnet 192.168.0.0/24 --gateway 192.168.0.10 publicNet

Then I create a container test:

sudo docker run --rm -dit --privileged -network publicNet --name my-macvlan-alpine --ip="192.168.0.48" alpine:latest ash

(I use privileged to add a route, better idea?)

Now I try to ping (ping 192.168.0.48) my container from two locations:

  • From another server on 192.168.0.0/24 network OK
  • From a client of the VPN: KO

So I thought I needed to add the route I added in my VM

$ sudo docker exec -it my-macvlan-alpine ash -c "ip route add 12.20.0.0/24 via 192.168.0.150 && ip route"
default via 192.168.0.10 dev eth0 
12.20.0.0/24 via 192.168.0.150 dev eth0 
192.168.0.0/24 dev eth0 scope link  src 192.168.0.48 

Still, I can't ping from my VPN client computer

What am I doing wrong?

Thanks,

xibi
  • 101
  • 1
  • 8

0 Answers0