dperson / openvpn-client

GNU Affero General Public License v3.0
1.06k stars 589 forks source link

Unable to communicate between two containers using the VPN by name #245

Closed doug-w closed 4 years ago

doug-w commented 4 years ago

Hi,

I have two containers that normally would talk to each-other through their container-name. When run under network_mode in a docker-compose.xml, there's no name resolution to the other containers also in the the same network_mode. However, I can resolve the names of other containers in the same docker-compose.yml file.

If I try to add a link in the compose-file it fails to start.
If I try extra_hosts specifying 127.0.0.1 it fails to start.

I've taken to changing references to host/ports in the container to be instead to 127.0.0.1:port.

Is there a way so container A on VPN V can ping container B also on VPN V?

Trimmed down docker-compose file:

services:
  vpn:
    container_name: vpn
    restart: always
    image: dperson/openvpn-client
    volumes:
     - ovpn-data-zappa:/vpn
    cap_add:
      - NET_ADMIN
    devices:
      - /dev/net/tun:/dev/net/tun
    dns:
      - 8.8.8.8
      - 8.8.4.4
    environment:
      - VPNPORT_1=23
      - VPNPORT_2=2777
      - VPNPORT_3=80
      - VPNPORT_4=443
  A:
    container_name: A
    image: linuxserver/letsencrypt
    restart: always
    privileged: true
    network_mode: "service:vpn"
  B:
    container_name: B
    image: dougw/tsunami
    restart: always
    network_mode: "service:vpn"
dperson commented 4 years ago

When they are both using the VPN containers network stack, it is functionally localhost for them.

hsklia commented 4 years ago

So what is the solution?

doug-w commented 4 years ago

Not ideal, I hardcoded 'vpn' as the hostname in my above example. That let A talk to B and B to A. I still wish that add-host had worked though.