Convers OpenVPN connection to SOCKS5 server in Docker. This allows you to have multiple OpenVPN to SOCKS5 proxies in different containers and expose to different host ports.
Supports latest Docker for both Windows, Linux, and MacOS.
- openvpn-tunnel (GitHub) - Wraps your program with OpenVPN network tunnel fully contained in Docker. It's the base image of this project.
- openvpn-socks5 (GitHub) - This project.
- shadowsocksr-tunnel (GitHub) - Wraps your program with ShadowsocksR network tunnel fully contained in Docker. Also exposes SOCKS5 server to host machine.
- shadowsocksr-aria2 (GitHub) - Extends
shadowsocksr-tunnel
witharia2
support.
- It reads in an OpenVPN configuration file (
.ovpn
) from a mounted file, specified throughOPENVPN_CONFIG
environment variable. - It starts the OpenVPN client program to establish the VPN connection.
- It starts the SOCKS5 server and listen on container-scoped port 1080 on default. SOCKS5 authentication can be enabled with
SOCKS5_USER
andSOCKS5_PASS
environment variables.SOCKS5_PORT
can be used to change the default port. - It optionally executes the user specified CMD line from
docker run
positional arguments (see Docker doc). The program will use the VPN connection inside the container. - If user has provided CMD line, and
DAEMON_MODE
environment variable is not set totrue
, then after running the CMD line, it will shutdown the OpenVPN client and terminate the container.
Since it extends the openvpn-tunnel (GitHub) image, everything in openvpn-tunnel
's document are still applicable on this image. Therefore, here we only provide an example that starts a daemon server that connects to VPN defined in file ./vpn.ovpn
on host machine, and expose the SOCKS5 to host-scoped port at 7777
.
# Unix
SET NAME="mysocks5"
PORT="7777"
USER="myuser"
PASS="mypass"
docker run --name "${NAME}" -dit --rm --device=/dev/net/tun --cap-add=NET_ADMIN \
-v "${PWD}":/vpn:ro -e OPENVPN_CONFIG=/vpn/vpn.ovpn \
-p "${PORT}":1080 \
-e SOCKS5_USER="${USER}" \
-e SOCKS5_PASS="${PASS}" \
curve25519xsalsa20poly1305/openvpn-socks5
# Windows
SET NAME="mysocks5"
SET PORT="7777"
SET USER="myuser"
SET PASS="mypass"
docker run --name "%NAME%" -dit --rm --device=/dev/net/tun --cap-add=NET_ADMIN ^
-v "%CD%":/vpn:ro -e OPENVPN_CONFIG=/vpn/vpn.ovpn ^
-p "%PORT%":1080 ^
-e SOCKS5_USER="%USER%" ^
-e SOCKS5_PASS="%PASS%" ^
curve25519xsalsa20poly1305/openvpn-socks5
Then on your host machine test it with curl:
# Unix & Windows
curl ifconfig.co/json -x socks5h://myuser:[email protected]:7777
To stop the daemon, run this:
# Unix
NAME="mysocks5"
docker stop "${NAME}"
# Windows
SET NAME="mysocks5"
docker stop "%NAME%"
Please feel free to contribute to this project. But before you do so, just make sure you understand the following:
1. Make sure you have access to the official repository of this project where the maintainer is actively pushing changes. So that all effective changes can go into the official release pipeline.
2. Make sure your editor has EditorConfig plugin installed and enabled. It's used to unify code formatting style.
3. Use Conventional Commits 1.0.0-beta.2 to format Git commit messages.
4. Use Gitflow as Git workflow guideline.
5. Use Semantic Versioning 2.0.0 to tag release versions.
Copyright © 2019 curve25519xsalsa20poly1305 <[email protected]>
This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See the COPYING file for more details.