2

I am trying to create a docker image which has a python script that connects to an API through VPN using openVPN, however, I cannot seem to get openVPN to be working.

I my docker file I have

# Install openVPN and get confi files
RUN mkdir /config
ADD ./config/. /config
RUN apt-get install -y openvpn 

# Run openvpn and script
CMD openvpn --config config/fremsyn.ovpn --auth-user-pass config/login.txt --askpass config/password.conf && python3 src/cli/getStatus.py

But I keep getting the error:

ERROR: Cannot open TUN/TAP dev /dev/net/tun: No such file or directory (errno=2)

Is there a solution to this problem?

As a side note, I need to run the container as container instance in Azure.

Martin Petri Bagger
  • 2,187
  • 4
  • 17
  • 20

2 Answers2

3
  1. Run ovpn with a deamon in Dockerfile
CMD openvpn --daemon --config config/fremsyn.ovpn --auth-user-pass config/login.txt --askpass config/password.conf && python3 src/cli/getStatus.py
  1. For run the service use docker-compose.yml like this :

docker-compose.yml

version: "3.3"
services: 
  name_of_your_service:
    image: your_image_from_Dockerfile_build
    restart: always
    sysctls:
      - net.ipv6.conf.all.disable_ipv6=0
    cap_add: 
      - NET_ADMIN
    devices:
      - /dev/net/tun
    volumes:
      - /etc/timezone:/etc/timezone:ro

Run command

 $ docker-compose up -d
  • When I try to build and push to Azure Container Registry using Devops Pipelines, the docker compose seems to take forever and I get the following message: "The image for the service you're trying to recreate has been removed. If you continue, volume data could be lost. Consider backing up your data before continuing." (I did change the name of the image) – Martin Petri Bagger Jun 22 '21 at 10:59
  • I needed this solution for docker-compose so that I could run sshuttle inside the container – Jono Aug 12 '22 at 11:38
1

Try running your container with additional capability called NET_ADMIN. Also mount the /dev/net/tun device.

docker run --cap-add NET_ADMIN -v /dev/net/tun:/dev/net/tun …
Mike Doe
  • 16,349
  • 11
  • 65
  • 88