OpenVPN server in a Docker container

Thursday, Feb 1, 2024 | 2 minute read | Updated at Wednesday, May 13, 2026

OpenVPN server in a Docker container

Here’s a Docker Compose file for OpenVPN

find a name starting with “ovpn-data-” for the volume, e.g. ovpn-data-example choose a domain name, e.g. VPN.SERVERNAME.COM

version: '3'
services:
  openvpn:
    image: kylemanna/openvpn
    container_name: openvpn
    ports:
      - "1194:1194/udp"
    cap_add:
      - NET_ADMIN
    volumes:
      - ovpn-data-example:/etc/openvpn
    restart: always

volumes:
  ovpn-data-example:

Save this content in a file named docker-compose.yml and then you can use the following commands:

  1. Create the volume:
OVPN_DATA=ovpn-data-example # change to your value
SERVER_NAME=VPN.SERVERNAME.COM

docker volume create --name $OVPN_DATA
docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://$SERVER_NAME
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
  1. Run the OpenVPN configuration:

Generate a client certificate without a passphrase for each user

CLIENTNAME=Alice

docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full $CLIENTNAME nopass

Retrieve the client configuration with embedded certificates for each user

docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient $CLIENTNAME > $CLIENTNAME.ovpn

You will have a Alice.ovpn to give to use in any openVPN client.

  1. Start the OpenVPN server:
docker-compose up -d

This Docker Compose file defines a service named openvpn using the kylemanna/openvpn image. It maps the UDP port 1194 on the host to the container and adds the NET_ADMIN capability. The volume named ovpn-data-example is mounted to persist the OpenVPN configuration and keys. The service is set to restart always to ensure it starts automatically on system boot.

Make sure to replace VPN.SERVERNAME.COM with your actual VPN server’s domain or IP address.

Get a OpenVPN client

https://openvpn.net/client/

More?

Read more at https://hub.docker.com/r/kylemanna/openvpn

© 1997 - 2026 Cédric Walter blog

🌱 Powered by Hugo with theme Dream.

Others

If you like my work or find it helpful, please consider buying me a cup of coffee ☕️. It inspires me to create and maintain more projects in the future. 🦾

It is better to attach some information or leave a message so that I can record the donation 📝 , thank you very much 🙏.

Copyright information

All editorial content and graphics on our sites are protected by U.S. copyright, international treaties, and other applicable copyright laws and may not be copied without the express permission of Cedric Walter, which reserves all rights. Reuse of any of Cedric Walter editorial content and graphics for any purpose without The author ’s permission is strictly prohibited.

DO NOT copy or adapt the HTML or other code that this site creates to generate pages. It also is covered by copyright.

Reproduction without explicit permission is prohibited. All Rights Reserved. All photos remain copyright © their rightful owners. No copyright infringement is intended.

Disclaimer: The editor(s) reserve the right to edit any comments that are found to be abusive, offensive, contain profanity, serves as spam, is largely self-promotional, or displaying attempts to harbour irrelevant text links for any purpose.

About me

Cédric Walter is a French-Swiss software engineer based in Zurich, Switzerland. PGP: DF52 ADDA C81A 08A6