1
version: '3.6'

services:
  vpn-proxy: # docker exec -it vpn-proxy /bin/sh
    container_name: vpn-proxy
    build:
      context: ../../vpn-proxy
      dockerfile: Dockerfile
    ports:
      - "127.0.0.1:13194:13194"
    logging:
      driver: json-file
    #command: -v UDP4-RECVFROM:13194,fork UDP4-SENDTO:172.17.0.1:1194
    command: TCP-LISTEN:13194,fork TCP:172.17.0.1:1194
    restart: always
  openvpn: # docker exec -it openvpn /bin/sh
    image: kylemanna/openvpn
    container_name: openvpn
    environment:
      DEBUG: '0'
    ports:
      - "1194:1194/udp"
    volumes:
      - ../../openvpn/scripts:/scripts
      - ../../data/output:/output
    network_mode: host
    cap_add:
      - NET_ADMIN
    command: /scripts/run-vpn.sh
    restart: always

ERROR: for openvpn "host" network_mode is incompatible with port_bindings docker.errors.InvalidArgument: "host" network_mode is incompatible with port_bindings

When I run my up.sh file, I get the error as above.

1 Answer 1

7

The error message is telling you that you can't use network_mode: host and ports in the same service, you need to make a choice.

Your openvpn service has a 1194:1194/udp port binding. This is used to bind a port of the host to a port of the container. But as you used the host networking mode, the container will use the host's networking interfaces, making your port bindings useless as the container will have access to the host's ports.

You could remove the ports section of your service but as the host networking mode is generally not recommended you should try to use port bindings instead.

3
  • Can you share an example of how I should edit?
    – Erraz Tone
    Aug 24, 2021 at 11:12
  • 1
    Delete the line that says network_mode: host.
    – David Maze
    Aug 24, 2021 at 11:21
  • network_mode: tunnelblick won't connect to vpn after deleting host
    – Erraz Tone
    Aug 24, 2021 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.