A containerized version of ocserv (OpenConnect VPN server), built from source for security, flexibility, and minimal overhead.
This project provides an easy-to-deploy VPN server with support for port forwarding to VPN clients, basic NAT out of the box, and optional Prometheus metrics export via ocserv-exporter for real-time monitoring and alerting.
- β¨ Features
- π Project Structure
- π¦ Installation
- βοΈ Configuration
- π Running the Container
- π§ Roadmap
- π Contributing
- π¬ Support
- π License
- π Repository Insights
- π³ Fully containerized via Docker & Compose
- β
Lightweight image built from
debian:bookworm-slim - π¦ Multi-stage Docker build with optimized final image size
- π Builds latest
ocservv1.3.0 from source with upstream GPG signature verification - βοΈ Includes default
ocserv.conffor quick setup and customization - π Uses s6-overlay for process supervision and service orchestration
- π Supports dynamic TCP/UDP port forwarding to VPN clients
- π Optional Prometheus metrics export via
ocserv-exporter - π‘ Custom healthcheck script validates both
ocservandocserv-exporter - π§ͺ Integrated GitHub Actions CI for build and image integrity testing
- π Licensed under GPLv3
ocserv-docker/
βββ .github/workflows/
β βββ docker-publish.yml # CI for Docker image publishing
βββ config/
β βββ ocserv.conf # ocserv default config
βββ rootfs/
β βββ usr/local/bin/ # Scripts (e.g. healthcheck)
β βββ etc/s6-overlay/ # s6 service definitions
βββ .dockerignore # Files to exclude from Docker build
βββ .env # Environment variables for Compose
βββ docker-compose.yml # Local dev/test setup
βββ Dockerfile # Docker image build instructions
βββ LICENSE # Project license (GPLv3)
βββ Makefile # Build commands
βββ README.md # Project documentation
curl -sSL https://get.docker.com | shgit clone https://github.com/gifi71/ocserv-docker.git /opt/ocserv-docker
cd /opt/ocserv-dockerCustomize it to fit your network and authentication setup. The default config is located at:
config/ocserv.conf
Important:
β οΈ Make sure the following setting is present and enabled in yourocserv.conf:
use-occtl = true
This setting enables the occtl command interface, which is required for the custom healthcheck script to verify ocserv status and for the ocserv-exporter to collect Prometheus metrics. Without it, both health monitoring and metrics export will not function correctly.
| Variable | Description | Default |
|---|---|---|
PORTS |
Space-separated list of port forwards in <host>:<client>:<port> |
Not set |
EXPORTER_ENABLED |
Enable ocserv-exporter for Prometheus metrics |
0 |
EXPORTER_INTERVAL |
Scrape interval for exporter | 30s |
EXPORTER_BIND |
Exporter listen address | 0.0.0.0:8000 |
Example:
PORTS="80:10.10.0.2:80 25565:10.10.0.3:25565"
EXPORTER_ENABLED=1
EXPORTER_INTERVAL=30s
EXPORTER_BIND=0.0.0.0:8000This will forward traffic on ports 80 and 25565 from the container to the specified VPN clients and serve prometheus metric (see ocserv-exporter for details) at http://0.0.0.0:8000/metrics.
You can customize basic settings without breaking functionality, such as:
- Ports: Change or add host ports to avoid conflicts or expose different VPN ports.
- Volumes: Modify the config folder path if your
ocserv.confor other files are stored elsewhere. - Container name: Rename the container if you run multiple instances.
- Logging options: Adjust log file size or rotation limits if needed.
To improve TCP performance, especially when using TCP VPN connections, you can enable the following settings by editing /etc/sysctl.conf:
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
Apply the changes with:
sysctl -pThese settings optimize packet scheduling and enable the BBR TCP congestion control algorithm, which can significantly enhance TCP throughput and reduce latency. This optimization is particularly useful if your VPN clients mainly use TCP connections.
Start the VPN server:
docker compose up -dView container logs:
docker compose logs -f ocservYou can also run the container directly with docker run:
docker run -d \
--name ocserv \
--restart unless-stopped \
--cap-add=NET_ADMIN \
--device /dev/net/tun:/dev/net/tun \
--sysctl net.ipv4.ip_forward=1 \
-p 443:443/tcp \
-p 443:443/udp \
--env-file .env \
-v "$(pwd)/config:/etc/ocserv" \
--security-opt no-new-privileges \
ghcr.io/gifi71/ocserv-docker:latestYou can build the Docker image locally using the provided Makefile target:
make oci-imageThis runs:
docker buildx build --progress=plain --pull -t ghcr.io/gifi71/ocserv-docker:latest .which builds the image with detailed output and tags it with ghcr.io/gifi71/ocserv-docker:latest.
- Multi-stage build (430MB -> 113MB)
- Published to GHCR
-
s6-overlaysupervision -
ocserv-exporterintegration - Extended healthcheck
- CI tests for image validation
Contributions, issues and feature requests are welcome!
Feel free to check the issues page or submit a pull request.
If you find this project useful, feel free to star it π and share it.
For questions or help, open an issue.
This project includes ocserv, licensed under GNU GPLv3. All derivative works must also be distributed under GPLv3.