Docker-openvpn: VPN access via container names

Created on 5 May 2017  路  3Comments  路  Source: kylemanna/docker-openvpn

Hi.

Is there some way, how I can access from my VPN client to containers via hostnames on the same docker network like this openVPN is?

Basicaly. I have this openVPN container and on the same network I have container with hostname gitlab. When I connect from my home PC, I want to have access to this gitlab container via http://gitlab.

When I am connected to VPN, I can access this containers via IP on docker subnet (172.26.x.x). But I can't connect to docker DNS.

I did changes to respect DNS from resolv.conf (pull request), so openVPN push to config DNS IP 127.0.0.11, but it doesn't seem to work.

I think it's because my client try to access DNS directly to 127.0.0.11. So my idea is to forward [SERVER_VPN_IP]:53 to 127.0.0.11:53. BTW, when I am connected like this, internet on my client PC don't work.

Any idea how to do it?

Thank you.

Most helpful comment

Hi,you can access your container inside your openvpn connection using defreitas/dns-proxy-server image using address like : containername.docker.
I made it with a docker network and you must be able to access your container via ip already.

docker-compose:
```
dnsproxy:
image: defreitas/dns-proxy-server
container_name: dnsproxy
restart: always
networks:
yournetwork:
ipv4_address: 172.18.x.x
environment:
- "MG_REGISTER_CONTAINER_NAMES=1"
volumes:
# uncomment to modify host resolv.conf and access docker from host with name
#- /etc/resolv.conf:/etc/resolv.conf
- /var/run/docker.sock:/var/run/docker.sock

networks:
yournetwork:
driver: bridge
ipam:
config:
- subnet: 172.18.0.0/16

docker-run:

docker run --rm --name dnsproxy -v /var/run/docker.sock:/var/run/docker.sock -v /etc/resolv.conf:/etc/resolv.conf --net yournetworkname -e MG_REGISTER_CONTAINER_NAMES=1 defreitas/dns-proxy-server
```

Don't forget to push your dns-proxy-server ip in your openvn.conf
push "dhcp-option DNS dns-proxy-server-proxy-internal-ip"

You might need to give name a with --name to access your container. I never tried without.

All 3 comments

I guess you need to run a DNS forwarder (such as dnsmasq) on the same Docker network than you run your OpenVPN server. This DNS forwarder should be configured to listen on a static IP of this Docker network which you should be able to access from your VPN clients. The DNS forwarder should forward all requests to 127.0.0.11.

But this has the limitation that it will only resolve DNS queries which the Docker DNS resolver can. So potentially you can resolve queries for internet public hosts and hosts local to the OpenVPN server LAN (including the Docker container). But suddenly you will not be able to resolve hosts from your local VPN client LAN.

Hi,you can access your container inside your openvpn connection using defreitas/dns-proxy-server image using address like : containername.docker.
I made it with a docker network and you must be able to access your container via ip already.

docker-compose:
```
dnsproxy:
image: defreitas/dns-proxy-server
container_name: dnsproxy
restart: always
networks:
yournetwork:
ipv4_address: 172.18.x.x
environment:
- "MG_REGISTER_CONTAINER_NAMES=1"
volumes:
# uncomment to modify host resolv.conf and access docker from host with name
#- /etc/resolv.conf:/etc/resolv.conf
- /var/run/docker.sock:/var/run/docker.sock

networks:
yournetwork:
driver: bridge
ipam:
config:
- subnet: 172.18.0.0/16

docker-run:

docker run --rm --name dnsproxy -v /var/run/docker.sock:/var/run/docker.sock -v /etc/resolv.conf:/etc/resolv.conf --net yournetworkname -e MG_REGISTER_CONTAINER_NAMES=1 defreitas/dns-proxy-server
```

Don't forget to push your dns-proxy-server ip in your openvn.conf
push "dhcp-option DNS dns-proxy-server-proxy-internal-ip"

You might need to give name a with --name to access your container. I never tried without.

@jribal Thank you. That was exactly what I was looking for. :-).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

degritsenko picture degritsenko  路  3Comments

lucaszanella picture lucaszanella  路  7Comments

jkroepke picture jkroepke  路  7Comments

ebarault picture ebarault  路  4Comments

josjaf picture josjaf  路  5Comments