kylemanna / docker-openvpn

🔒 OpenVPN server in a Docker container complete with an EasyRSA PKI CA
https://hub.docker.com/r/kylemanna/openvpn/
MIT License
8.68k stars 2.38k forks source link

docker-compose /usr/local/bin/ovpn_initpki: line 13: /etc/openvpn/ovpn_env.sh: No such file or directory #604

Open istvankerek opened 3 years ago

istvankerek commented 3 years ago

Hello, I use this docker-compose.yml but not working for me I got error. Please help me If it is possible. Thank you!


services:
  openvpn:
    cap_add:
        - NET_ADMIN
    image: kylemanna/openvpn
    container_name: openvpn
    ports:
        - "1194:1194/udp"
    restart: always
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./data/openvpn:/etc/openvpn"
      - ./data/logs:/tmp"

When I try to run this command on Ubuntu 20.04 terminal I got this message:

docker-compose run --rm openvpn ovpn_genconfig -u udp://my.domain.tld

Processing PUSH Config: 'block-outside-dns'
Processing Route Config: '192.168.254.0/24'
Processing PUSH Config: 'dhcp-option DNS 8.8.8.8'
Processing PUSH Config: 'dhcp-option DNS 8.8.4.4'
Processing PUSH Config: 'comp-lzo no'
Successfully generated config
Cleaning up before Exit ...

When I run ovpn_initpki I got this message

docker-compose run --rm openvpn ovpn_initpki
/usr/local/bin/ovpn_initpki: line 13: /etc/openvpn/ovpn_env.sh: No such file or directory

I use docker as root, the folders made by root and owned too. The 1194 port is opened.

I tryed this too: (https://github.com/kylemanna/docker-openvpn/issues/35#issuecomment-478297237)

I made a bash file (addUser.sh) to generate .ovpn files

#!/bin/bash

# To run with Argoment
# sh addUser.sh username

if [ -z "${1}" ]
then
      echo "Argoment is empty please add a Username to continue!"
      read -p 'Username: ' uservar
      CLIENTNAME=${uservar}
else
      echo "${1} will be the Username"
      CLIENTNAME=${1}
fi

docker-compose run --rm openvpn easyrsa build-client-full ${CLIENTNAME}
mkdir -p ./data/ovpns
docker-compose run --rm openvpn ovpn_getclient ${CLIENTNAME} > ./data/ovpns/${CLIENTNAME}.ovpn

echo ovpn file is generated:
echo ${PWD}/data/ovpns/${CLIENTNAME}.ovpn

But I got this errors inside the files

sh addUser.sh username

username will be the Username

Easy-RSA error:

EASYRSA_PKI does not exist (perhaps you need to run init-pki)?
Expected to find the EASYRSA_PKI at: /etc/openvpn/pki
Run easyrsa without commands for usage and command help.
ovpn file is generated:
./data/ovpns/username.ovpn

/usr/local/bin/ovpn_getclient: line 16: /etc/openvpn/ovpn_env.sh: No such file or directory
Could not source /etc/openvpn/ovpn_env.sh.

When I run Debugging Tips I got this message

docker-compose run -e DEBUG=1 -p 1194:1194/udp openvpn
+ set -e
+ cd /etc/openvpn
+ USER_ARGS=("${@}")
+ ARGS=()
+ addArg --config /etc/openvpn/openvpn.conf
+ local arg=--config
+ '[' 2 -ge 1 ']'
+ local val=/etc/openvpn/openvpn.conf
+ hasArg --config
+ local element
+ return 1
+ ARGS+=("${arg}")
+ '[' 2 -ge 1 ']'
+ ARGS+=("${val}")
+ source /etc/openvpn/ovpn_env.sh
/usr/local/bin/ovpn_run: line 55: /etc/openvpn/ovpn_env.sh: No such file or directory

When I run logs I got this message

docker-compose logs -f
Attaching to openvpn
openvpn    | /usr/local/bin/ovpn_run: line 55: /etc/openvpn/ovpn_env.sh: No such file or directory
openvpn    | /usr/local/bin/ovpn_run: line 55: /etc/openvpn/ovpn_env.sh: No such file or directory
openvpn    | /usr/local/bin/ovpn_run: line 55: /etc/openvpn/ovpn_env.sh: No such file or directory
openvpn    | /usr/local/bin/ovpn_run: line 55: /etc/openvpn/ovpn_env.sh: No such file or directory
openvpn exited with code 1

I made something in a wrong way or this is a bug?

joej commented 3 years ago

Its Oct 18th ... just tried getting this docker running.

same issues - missing /vars file (read the issues) ... missing ovpn_env.sh (read the issues).

Can we get a good, working version somewhere?

skupjoe commented 2 years ago

Same issue! ovpn_env.sh is completely missing! How do I use this container?

dayjaby commented 2 years ago

@skupjoe Make sure to use docker compose version >= 3.2 and use bind instead of volume for the /etc/openvpn/ path.

skupjoe commented 2 years ago

Hi @dayjaby -

Thanks. I tried this (I was previously on 2.4), but I still experienced the same issue.

Ultimately, I needed to create an empty ovpn_env.sh file and mount this to /etc/openvpn/ovpn_env.sh to get passed the error.

skupjoe commented 2 years ago

I think the error is due to using bind mounts on the /etc/openvpn directory. If you do this, then this will replace any built-in volumes on that directory which the container is already using.

For me, the issue is further compounded because I am using openvpn in client mode only and I am supplying my own openvpn.conf via bind mount:

    volumes:
      - /svc/openvpn/etc/openvpn.conf:/etc/openvpn/openvpn.conf
      - /svc/openvpn/etc/ovpn_env.sh:/etc/openvpn/ovpn_env.sh

I am not really using any of the /bin scripts and I didn't perform the steps in the Quick Start, so maybe ovpn_env.sh gets created in the process.

skupjoe commented 2 years ago

Side note I also found that I needed to set the following to get the container to boot, likely because some env's aren't being set via the missing ovpn_env.sh :

    environment:
      - OVPN_SERVER=${IPADDR}

Thankfully, this was all I needed to get passed the boot error and have openvpn run fine in client-only mode.

kasir-barati commented 1 year ago

@istvankerek Can you add more details on what would be in the IPADDR env?

russalex83 commented 1 year ago

Hi @dayjaby -

Thanks. I tried this (I was previously on 2.4), but I still experienced the same issue.

Ultimately, I needed to create an empty ovpn_env.sh file and mount this to /etc/openvpn/ovpn_env.sh to get passed the error.

Can you tell us how you did it? Thanks!

skupjoe commented 1 year ago

Hi @dayjaby - Thanks. I tried this (I was previously on 2.4), but I still experienced the same issue. Ultimately, I needed to create an empty ovpn_env.sh file and mount this to /etc/openvpn/ovpn_env.sh to get passed the error.

Can you tell us how you did it? Thanks!

Sure-

You can use a volume mount in your docker-compose.yaml as so:

  openvpn:
    image: kylemanna/openvpn:latest
    container_name: openvpn
    hostname: openvpn
    cap_add:
      - NET_ADMIN
      - NET_RAW
    volumes:
      - ./bin/ovpn_env.sh:/etc/openvpn/ovpn_env.sh

In my situation, I am actually providing a bash script for this file that has some custom things that I do when provisioning this image. But if you don't have an actual script at ./bin/ovpn_env.sh then it will mount a blank file which I think should work fine.

Let me know if you run into any trouble.