Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit 8524af6

Browse files
author
wfg
committed
Update README.md
1 parent 82ad57d commit 8524af6

File tree

1 file changed

+59
-33
lines changed

1 file changed

+59
-33
lines changed

README.md

Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,76 @@
11
# OpenVPN Client for Docker
22
## What is this and what does it do?
3-
[`ghcr.io/wfg/openvpn-client`](https://github.com/users/wfg/packages/container/package/openvpn-client) is a containerized OpenVPN client. It has a kill switch built with `iptables` that kills Internet connectivity to the container if the VPN tunnel goes down for any reason. It also includes an HTTP proxy server ([Tinyproxy](https://tinyproxy.github.io/)) and a SOCKS proxy server ([Dante](https://www.inet.no/dante/index.html)). This allows hosts and non-containerized applications to use the VPN without having to run VPN clients on those hosts.
3+
[`ghcr.io/wfg/openvpn-client`](https://github.com/users/wfg/packages/container/package/openvpn-client) is a containerized OpenVPN client.
4+
It has a kill switch built with `iptables` that kills Internet connectivity to the container if the VPN tunnel goes down for any reason.
5+
It also includes an HTTP proxy server ([Tinyproxy](https://tinyproxy.github.io/)) and a SOCKS proxy server ([Dante](https://www.inet.no/dante/index.html)).
6+
This allows hosts and non-containerized applications to use the VPN without having to run VPN clients on those hosts.
47

5-
This image requires you to supply the necessary OpenVPN configuration file(s). Because of this, any VPN provider should work (however, if you find something that doesn't, please open an issue for it).
8+
This image requires you to supply the necessary OpenVPN configuration file(s).
9+
Because of this, any VPN provider should work.
10+
11+
If you find something that doesn't work or have an idea for a new feature, issues and **pull requests are welcome**.
612

713
## Why?
8-
Having a containerized VPN client lets you use container networking to easily choose which applications you want using the VPN instead of having to set up split tunnelling. It also keeps you from having to install an OpenVPN client on the underlying host.
14+
Having a containerized VPN client lets you use container networking to easily choose which applications you want using the VPN instead of having to set up split tunnelling.
15+
It also keeps you from having to install an OpenVPN client on the underlying host.
916

10-
The idea for this image came from a similar project by [qdm12](https://github.com/qdm12) that has since evolved into something bigger and more complex than I wanted to use. I decided to dissect it and take it in my own direction. I plan to keep everything here well-documented because I want this to be a learning experience for both me and hopefully anyone else that uses it.
17+
The idea for this image came from a similar project by [qdm12](https://github.com/qdm12) that has since evolved into something bigger and more complex than I wanted to use.
18+
I decided to dissect it and take it in my own direction.
19+
I plan to keep everything here well-documented so this is not only a learning experience for me, but also anyone else that uses it.
1120

1221
## How do I use it?
1322
### Getting the image
1423
You can either pull it from GitHub Container Registry or build it yourself.
1524

16-
To pull from GitHub Container Registry, run `docker pull ghcr.io/wfg/openvpn-client`.
25+
To pull it from GitHub Container Registry, run
26+
```bash
27+
docker pull ghcr.io/wfg/openvpn-client
28+
```
1729

18-
To build it yourself, do the following:
30+
To build it yourself, run
1931
```bash
20-
git clone https://github.com/wfg/docker-openvpn-client.git
21-
cd docker-openvpn-client
22-
docker build -t ghcr.io/wfg/openvpn-client .
32+
docker build -t ghcr.io/wfg/openvpn-client https://github.com/wfg/docker-openvpn-client.git
2333
```
2434

2535
### Creating and running a container
26-
The image requires the container be created with the `NET_ADMIN` capability and `/dev/net/tun` accessible. Below are bare-bones examples for `docker run` and Compose; however, you'll probably want to do more than just run the VPN client. See the sections below to learn how to use the [proxies](#http_proxy-and-socks_proxy) and have [other containers use `openvpn-client`'s network stack](#using-with-other-containers).
36+
The image requires the container be created with the `NET_ADMIN` capability and `/dev/net/tun` accessible.
37+
Below are bare-bones examples for `docker run` and Compose; however, you'll probably want to do more than just run the VPN client.
38+
See the sections below to learn how to use the [proxies](#http_proxy-and-socks_proxy) and have [other containers use `openvpn-client`'s network stack](#using-with-other-containers).
2739

2840
#### `docker run`
2941
```bash
30-
docker run -d \
42+
docker run --detach \
3143
--name=openvpn-client \
3244
--cap-add=NET_ADMIN \
3345
--device=/dev/net/tun \
34-
-v <path/to/config>:/data/vpn \
46+
--env KILL_SWITCH=off \
47+
--volume <path/to/config/dir>:/data/vpn \
3548
ghcr.io/wfg/openvpn-client
3649
```
3750

3851
#### `docker-compose`
3952
```yaml
40-
version: '2'
53+
version: "2.4"
4154

4255
services:
43-
openvpn-client:
44-
image: ghcr.io/wfg/openvpn-client
45-
container_name: openvpn-client
46-
cap_add:
47-
- NET_ADMIN
48-
devices:
49-
- /dev/net/tun
50-
volumes:
51-
- <path/to/config>:/data/vpn
52-
restart: unless-stopped
56+
openvpn-client:
57+
image: ghcr.io/wfg/openvpn-client
58+
container_name: openvpn-client
59+
cap_add:
60+
- NET_ADMIN
61+
devices:
62+
- /dev/net/tun
63+
environment:
64+
- KILL_SWITCH=off
65+
volumes:
66+
- <path/to/config/dir>:/data/vpn
67+
restart: unless-stopped
5368
```
5469
5570
#### Environment variables
5671
| Variable | Default (blank is unset) | Description |
5772
| --- | --- | --- |
73+
| `KILL_SWITCH` | `on` | The on/off status of the network kill switch. |
5874
| `SUBNETS` | | A list of one or more comma-separated subnets (e.g. `192.168.0.0/24,192.168.1.0/24`) to allow outside of the VPN tunnel. See important note about this [below](#subnets). |
5975
| `VPN_LOG_LEVEL` | `3` | OpenVPN verbosity (`1`-`11`) |
6076
| `HTTP_PROXY` | `off` | The on/off status of Tinyproxy, the built-in HTTP proxy server. To enable, set to `on`. Any other value (including unset) will cause the proxy server to not start. It listens on port 8080. |
@@ -64,39 +80,49 @@ services:
6480

6581
##### Environment variable considerations
6682
###### `SUBNETS`
67-
**Important**: The DNS server used by this container prior to VPN connection must be included in the value specified. For example, if your container is using 192.168.1.1 as a DNS server, then this address or an appropriate CIDR block must be included in `SUBNETS`. This is necessary because the kill switch blocks traffic outside of the VPN tunnel before it's actually established. If the DNS server is not allowed, the server addresses in the VPN configuration will not resolve.
83+
**Important**:
84+
If the kill switch is enabled, the DNS server used by this container prior to VPN connection must be included in the value specified.
85+
For example, if your container is using 192.168.1.1 as a DNS server, then this address or an appropriate CIDR block must be included in `SUBNETS`.
86+
This is necessary because the kill switch blocks traffic outside of the VPN tunnel before it's actually established.
87+
If the DNS server is not allowed, the server addresses in the VPN configuration will not resolve.
6888

6989
The subnets specified will be allowed through the firewall which allows for connectivity to and from hosts on the subnets.
7090

7191
###### `HTTP_PROXY` and `SOCKS_PROXY`
72-
If enabling the the proxy server(s), you'll want to publish the appropriate port(s) in order to access the server(s). To do that using `docker run`, add `-p <host_port>:8080` and/or `-p <host_port>:1080` where `<host_port>` is whatever port you want to use on the host. If you're using `docker-compose`, add the relevant port specification(s) from the snippet below to the `openvpn-client` service definition in your Compose file.
92+
If enabling the the proxy server(s), you'll want to publish the appropriate port(s) in order to access the server(s).
93+
To do that using `docker run`, add `-p <host_port>:8080` and/or `-p <host_port>:1080` where `<host_port>` is whatever port you want to use on the host.
94+
If you're using `docker-compose`, add the relevant port specification(s) from the snippet below to the `openvpn-client` service definition in your Compose file.
7395
```yaml
7496
ports:
75-
- <host_port>:8080
76-
- <host_port>:1080
97+
- <host_port>:8080
98+
- <host_port>:1080
7799
```
78100

79101
### Using with other containers
80-
Once you have your `openvpn-client` container up and running, you can tell other containers to use `openvpn-client`'s network stack which gives them the ability to utilize the VPN tunnel. There are a few ways to accomplish this depending how how your container is created.
102+
Once you have your `openvpn-client` container up and running, you can tell other containers to use `openvpn-client`'s network stack which gives them the ability to utilize the VPN tunnel.
103+
There are a few ways to accomplish this depending how how your container is created.
81104

82105
If your container is being created with
83106
1. the same Compose YAML file as `openvpn-client`, add `network_mode: service:openvpn-client` to the container's service definition.
84107
2. a different Compose YAML file than `openvpn-client`, add `network_mode: container:openvpn-client` to the container's service definition.
85108
3. `docker run`, add `--network=container:openvpn-client` as an option to `docker run`.
86109

87-
Once running and provided your container has `wget` or `curl`, you can run `docker exec <container_name> wget -qO - ifconfig.me` or `docker exec <container_name> curl -s ifconfig.me` to get the public IP of the container and make sure everything is working as expected. This IP should match the one of `openvpn-client`.
110+
Once running and provided your container has `wget` or `curl`, you can run `docker exec <container_name> wget -qO - ifconfig.me` or `docker exec <container_name> curl -s ifconfig.me` to get the public IP of the container and make sure everything is working as expected.
111+
This IP should match the one of `openvpn-client`.
88112

89113
#### Handling ports intended for connected containers
90-
If you have a connected container and you need to access a port that container, you'll want to publish that port on the `openvpn-client` container instead of the connected container. To do that, add `-p <host_port>:<container_port>` if you're using `docker run`, or add the below snippet to the `openvpn-client` service definition in your Compose file if using `docker-compose`.
114+
If you have a connected container and you need to access a port that container, you'll want to publish that port on the `openvpn-client` container instead of the connected container.
115+
To do that, add `-p <host_port>:<container_port>` if you're using `docker run`, or add the below snippet to the `openvpn-client` service definition in your Compose file if using `docker-compose`.
91116
```yaml
92117
ports:
93-
- <host_port>:<container_port>
118+
- <host_port>:<container_port>
94119
```
95120
In both cases, replace `<host_port>` and `<container_port>` with the port used by your connected container.
96121

97122
### Verifying functionality
98-
Once you have container running `ghcr.io/wfg/openvpn-client`, run the following command to spin up a temporary container using `openvpn-client` for networking. The `wget -qO - ifconfig.me` bit will return the public IP of the container (and anything else using `openvpn-client` for networking). You should see an IP address owned by your VPN provider.
123+
Once you have container running `ghcr.io/wfg/openvpn-client`, run the following command to spin up a temporary container using `openvpn-client` for networking.
124+
The `wget -qO - ifconfig.me` bit will return the public IP of the container (and anything else using `openvpn-client` for networking).
125+
You should see an IP address owned by your VPN provider.
99126
```bash
100127
docker run --rm -it --network=container:openvpn-client alpine wget -qO - ifconfig.me
101128
```
102-

0 commit comments

Comments
 (0)