Skip to content

SloCompTech/docker-openvpn

Repository files navigation

Features:

  • OpenVPN running as non-root user (limited permission)
  • Containerized (Isolated environment)
  • Easy managed (Helper scripts).
  • Easy start (Simple first-start guide).
  • Easly modified to your needs (see docs).
  • Easy scripting (python3 installed).

Usage

Here are some example snippets to help you get started creating a container.

docker

# Normal start command (but you need to setup config first)
docker run \
  --name=ovpn \
  --cap-add NET_ADMIN \
  -e PUID=1000 \
  -e GUID=1000 \
  -p 1194:1194/udp \
  -v </path/o/config>:/config \
  --restart=unless-stopped \
  --network host \
  slocomptech/openvpn:latest

docker-compose

version: '2.2'
services:
  ovpn:
    image: slocomptech/openvpn
    container_name: ovpn
    hostname: ovpn
    cap_add:
      - NET_ADMIN
    ports:
      - "1194:1194/udp"
    volumes:
      - ./data:/config
    environment:
      - PUID=1000
      - PGUID=1000
    restart: on-failure
    # If you want to build from source add build:
    build:
      context: .
      cache_from:
        - lsiobase/alpine.python3:latest
    networks:
      mynetwork:
        ipv4_address: 10.0.0.5
        ipv6_address: 2001:1111::5
    
networks:
  mynetwork:
    driver: host
    enable_ipv6: true

Parameters

Parameter Function
-e PUID=1000 for UserID - see below for explanation
-e PGID=1000 for GroupID - see below for explanation
-v /config All the config files including OpenVPNs reside here

User / Group Identifiers

When using volumes (-v flags) permissions issues can arise between the host OS and the container, we avoid this issue by allowing you to specify the user PUID and group PGID.

Ensure any volume directories on the host are owned by the same user you specify and any permissions issues will vanish like magic.

In this instance PUID=1000 and PGID=1000, to find yours use id user as below:

  $ id username
    uid=1000(dockeruser) gid=1000(dockergroup) groups=1000(dockergroup)

Application setup

Initial setup

If you are new to containers please see rather Detailed first setup guide, because it includes more detailed description.

  1. Init configuration directory with initial config files:
docker run -it --rm --cap-add NET_ADMIN -v </path/to/config>:/config slocomptech/openvpn:latest bash
  1. At this point you will have bash shell which runs in container. Now run following commands to setup your PKI:
ovpn_init [nopass] # Inits PKI
  1. Setup OpenVPN config based on example basic_nat with configuration wizard:
ovpn_enconf basic_nat
#Protocol udp, tcp, udp6, tcp6 [udp]:
#VPN network [10.0.0.0]:
#Port [1194]:
#Public IP or domain of server: <YOUR PUBLIC IP>
#DNS1 [8.8.8.8]:
#DNS2 [8.8.4.4]:
  1. Enable port forwarding on your router so OpenVPN server will be accessible from the internet.
  2. Add clients
# Generates client certificates
ovpn_client add <name> [nopass]

# Generates client config file and prints it to screen (redirect to file)
ovpn_client ovpn <name> > <config file>.ovpn

# OR BETTER SOLLUTION: Run outside container
docker exec -it <container name> ovpn_client ovpn <name> > <config file>.ovpn
  1. Exit container with exit, then it will destroy itself.
  2. Start container using command specified in Usage section.

For more infromation see:

  • Detailed first setup guide
  • docs (for detailed command usage)
  • configuration example directory (for more info about example)
  • Contributing (for explanation how container works, how to write an example config ...)

Troubleshooting

Contribute

Feel free to contribute new features to this container, but first see Contribute Guide.

TODO

Planed features:

Wanted features (please help implement):

  • LDAP authentication script
  • Google authenticator

Licenses

Versions

See CHANGELOG