Run openvpn on latest Alpine in Docker the easy way
10K+
Run openvpn on latest Alpine in Docker
If you simply want to use OpenVPN in a Docker container without additional bloat I found it hard to find something suitable and decided to build this workflow. Nothing special and a very naive, simplistic approach. Please let me know in case I missed something important.
Make sure you have port forwarding activated in the kernel.
Allow forwarding from and to the tunnel in your firewall, e.g.:
sudo iptables -A FORWARD -s 192.168.3.0/24 -m comment --comment OpenVPN -j ACCEPT
sudo iptables -A FORWARD -d 192.168.3.0/24 -m comment --comment OpenVPN -j ACCEPT
sudo iptables -A FORWARD -s 192.168.178.0/24 -m comment --comment OpenVPN -j ACCEPT
sudo iptables -A FORWARD -d 192.168.178.0/24 -m comment --comment OpenVPN -j ACCEPT
And -if everything works as expected - install iptables-persistent to make sure these settings survive a reboot:
apt-get install iptables-persistent
https://hub.docker.com/r/dachack/openvpn
https://github.com/DaCHack/openvpn-docker
Caution: Due to Dockerhub's web application firewall settings (cloudflare) I needed to mask the passwd and shadow file path mapping inside of the container. Please remove the underscores ("_") in the listing below! except for "NET_ADMIN"!
openvpn:
image: dachack/openvpn
container_name: "openvpn" # choose any name you like
stdin_open: true # docker run -i
tty: true # docker run -t
restart: unless-stopped # always restart in case of issues or system reboot
network_mode: "host" # as far as I read OpenVPN requires host network
ports:
- 1194:1194/udp
volumes:
- "/root/containers/openvpn:/etc/openvpn" # use your existing config here or create a new one based on OpenVPN config reference
- "/path/to/your/passwd:/etc/_p_ass_wd" # if using PAM auth simply use the users on the host for VPN login by linking/copying passwd and shadow files or create custom files based on the Alpine template
- "/path/to/your/shadow:/etc/_sha_dow" # see above
devices:
- "/dev/net/tun:/dev/net/tun" # Give permission to use the tunnel device of the host
cap_add:
- NET_ADMIN # as far as I read OpenVPN requires the capability
Content type
Image
Digest
sha256:09c2d49c1…
Size
9.5 MB
Last updated
about 16 hours ago
docker pull dachack/openvpn