By Kyle Manna and Sharon Campbell
This tutorial will explain how to set up and run an OpenVPN container with the help of Docker.
OpenVPN provides a way to create virtual private networks (VPNs) using TLS (evolution of SSL) encryption. OpenVPN protects the network traffic from eavesdropping and man-in-the-middle (MITM) attacks. The private network can be used to securely connect a device, such as a laptop or mobile phone running on an insecure WiFi network, to a remote server that then relays the traffic to the Internet. Private networks can also be used to securely connect devices to each other over the Internet.
Docker provides a way to encapsulate the OpenVPN server process and configuration data so that it is more easily managed. The Docker OpenVPN image is prebuilt and includes all of the necessary dependencies to run the server in a sane and stable environment. Scripts are included to significantly automate the standard use case, but still allow for full manual configuration if desired. A Docker volume container is used to hold the configuration and EasyRSA PKI certificate data as well.
Docker Registry is a central repository for both official and user developed Docker images. The image used in this tutorial is a user contributed image available at kylemanna/openvpn. The image is assembled on Docker Registry’s cloud build servers using the source from the GitHub project repository. The cloud server build linked to Github adds the ability to audit the Docker image so that users can review the source Dockerfile and related code, called a Trusted Build. When the code is updated in the GitHub repository, a new Docker image is built and published on the Docker Registry.
Docker is moving fast and Ubuntu’s long term support (LTS) policy doesn’t keep up. To work around this we’ll install a PPA that will get us the latest version of Docker.
Add the upstream Docker repository package signing key. The apt-key
command uses elevated privileges via sudo
, so a password prompt for the user’s password may appear:
curl -L https://get.docker.com/gpg | sudo apt-key add -
Note: Enter your sudo password at the blinking cursor if necessary.
Add the upstream Docker repository to the system list:
echo deb http://get.docker.io/ubuntu docker main | sudo tee /etc/apt/sources.list.d/docker.list
Update the package list and install the Docker package:
sudo apt-get update && sudo apt-get install -y lxc-docker
Add your user to the docker
group to enable communication with the Docker daemon as a normal user, where sammy
is your username. Exit and log in again for the new group to take effect:
sudo usermod -aG docker sammy
After re-logging in verify the group membership using the id
command. The expected response should include docker
like the following example:
uid=1001(test0) gid=1001(test0) groups=1001(test0),27(sudo),999(docker)
Optional: Run bash
in a simple Debian Docker image (--rm
to clean up container after exit and -it
for interactive) to verify Docker operation on host:
docker run --rm -it debian:jessie bash -l
Expected response from docker as it pulls in the images and sets up the container:
Unable to find image 'debian:jessie' locally
debian:jessie: The image you are pulling has been verified
511136ea3c5a: Pull complete
36fd425d7d8a: Pull complete
aaabd2b41e22: Pull complete
Status: Downloaded newer image for debian:jessie
root@de8ffd8f82f6:/#
Once inside the container you’ll see the root@<container id>:/#
prompt signifying that the current shell is in a Docker container. To confirm that it’s different from the host, check the version of Debian running in the container:
cat /etc/issue.net
Expected response for the OpenVPN container at the time of writing:
Debian GNU/Linux jessie/sid
If you see a different version of Debian, that’s fine.
Exit the container by typing logout
, and the host’s prompt should appear again.
This step is usually a headache for those familiar with OpenVPN or any services utilizing PKI. Luckily, Docker and the scripts in the Docker image simplify this step by generating configuration files and all the necessary certificate files for us.
Create a volume container. This tutorial will use the $OVPN_DATA
environmental variable to make it copy-paste friendly. Set this to anything you like. The default ovpn-data
value is recommended for single OpenVPN Docker container servers. Setting the variable in the shell leverages string substitution to save the user from manually replacing it for each step in the tutorial:
OVPN_DATA="ovpn-data"
Create an empty Docker volume container using busybox
as a minimal Docker image:
docker run --name $OVPN_DATA -v /etc/openvpn busybox
Initialize the $OVPN_DATA
container that will hold the configuration files and certificates, and replace vpn.example.com
with your FQDN. The vpn.example.com
value should be the fully-qualified domain name you use to communicate with the server. This assumes the DNS settings are already configured. Alternatively, it’s possible to use just the IP address of the server, but this is not recommended.
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_genconfig -u udp://vpn.example.com:1194
Generate the EasyRSA PKI certificate authority. You will be prompted for a passphrase for the CA private key. Pick a good one and remember it; without the passphrase it will be impossible to issue and sign client certificates:
docker run --volumes-from $OVPN_DATA --rm -it kylemanna/openvpn ovpn_initpki
Note, the security of the $OVPN_DATA
container is important. It contains all the private keys to impersonate the server and all the client certificates. Keep this in mind and control access as appropriate. The default OpenVPN scripts use a passphrase for the CA key to increase security and prevent issuing bogus certificates.
See the Conclusion below for more details on how to back up the certificate store.
To autostart the Docker container that runs the OpenVPN server process (see Docker Host Integration for more) create an Upstart init file using nano
or vim
:
sudo vim /etc/init/docker-openvpn.conf
Contents to place in /etc/init/docker-openvpn.conf
:
description "Docker container for OpenVPN server"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
script
exec docker run --volumes-from ovpn-data --rm -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
end script
Start the process using the Upstart init mechanism:
sudo start docker-openvpn
Verify that the container started and didn’t immediately crash by looking at the STATUS
column:
test0@tutorial0:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c3ca41324e1d kylemanna/openvpn:latest "ovpn_run" 2 seconds ago Up 2 seconds 0.0.0.0:1194->1194/udp focused_mestorf
In this section we’ll create a client certificate using the PKI CA we created in the last step.
Be sure to replace CLIENTNAME
as appropriate (this doesn’t have to be a FQDN). The client name is used to identify the machine the OpenVPN client is running on (e.g., “home-laptop”, “work-laptop”, “nexus5”, etc.).
The easyrsa
tool will prompt for the CA password. This is the password we set above during the ovpn_initpki
command. Create the client certificate:
docker run --volumes-from $OVPN_DATA --rm -it kylemanna/openvpn easyrsa build-client-full CLIENTNAME nopass
After each client is created, the server is ready to accept connections.
The clients need the certificates and a configuration file to connect. The embedded scripts automate this task and enable the user to write out a configuration to a single file that can then be transfered to the client. Again, replace CLIENTNAME
as appropriate:
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_getclient CLIENTNAME > CLIENTNAME.ovpn
The resulting CLIENTNAME.ovpn
file contains the private keys and certificates necessary to connect to the VPN. Keep these files secure and not lying around. You’ll need to securely transport the *.ovpn
files to the clients that will use them. Avoid using public services like email or cloud storage if possible when transferring the files due to security concerns.
Recommend methods of transfer are ssh/scp, HTTPS, USB, and microSD cards where available.
The following are commands or operations run on the clients that will connect to the OpenVPN server configured above.
On Ubuntu 12.04/14.04 and Debian wheezy/jessie clients (and similar):
Install OpenVPN:
sudo apt-get install openvpn
Copy the client configuration file from the server and set secure permissions:
sudo install -o root -m 400 CLIENTNAME.ovpn /etc/openvpn/CLIENTNAME.conf
Configure the init scripts to autostart all configurations matching /etc/openvpn/*.conf
:
echo AUTOSTART=all | sudo tee -a /etc/default/openvpn
Restart the OpenVPN client’s server process:
sudo /etc/init.d/openvpn restart
Install OpenVPN:
pacman -Sy openvpn
Copy the client configuration file from the server and set secure permissions:
sudo install -o root -m 400 CLIENTNAME.ovpn /etc/openvpn/CLIENTNAME.conf
Start OpenVPN client’s server process:
systemctl start openvpn@CLIENTNAME
Optional: configure systemd to start /etc/openvpn/CLIENTNAME.conf
at boot:
systemctl enable openvpn@CLIENTNAME
Download and install TunnelBlick.
Copy CLIENTNAME.ovpn
from the server to the Mac.
Import the configuration by double clicking the *.ovpn
file copied earlier. TunnelBlick will be invoked and the import the configuration.
Open TunnelBlick, select the configuration, and then select connect.
Install the OpenVPN Connect App from the Google Play store.
Copy CLIENTNAME.ovpn
from the server to the Android device in a secure manner. USB or microSD cards are safer. Place the file on your SD card to aid in opening it.
Import the configuration: Menu -> Import -> Import Profile from SD card
Select connect.
There are a few ways to verify that traffic is being routed through the VPN.
Visit a website to determine the external IP address. The external IP address should be that of the OpenVPN server.
Try Google “what is my ip” or icanhazip.com.
From the command line, wget
or curl
come in handy. Example with curl
:
curl icanhazip.com
Example with wget
:
wget -qO - icanhazip.com
The expected response should be the IP address of the OpenVPN server.
Another option is to do a special DNS lookup to a specially configured DNS server just for this purpose using host
or dig
. Example using host
:
host -t A myip.opendns.com resolver1.opendns.com
Example with dig
:
dig +short myip.opendns.com @resolver1.opendns.com
The expected response should be the IP address of the OpenVPN server.
Review your network interface configuration. On Unix-based operating systems, this is as simple as running ifconfig
in a terminal, and looking for OpenVPN’s tunX
interface when it’s connected.
Review logs. On Unix systems check /var/log
on old distributions or journalctl
on systemd distributions.
The Docker image built to run this is open source and capable of much more than described here.
The docker-openvpn source repository is available for review of the code as well as forking for modifications. Pull requests for general features or bug fixes are welcome.
Advanced topics such as backup and static client IPs are discussed under the docker-openvpn/docs folder.
Report bugs to the docker-openvpn issue tracker.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
I like to hack, break, and build things!
Current fan and former Editorial Manager at DigitalOcean. Hi! Expertise in areas including Ubuntu, Docker, Rails, and more.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Thanks for sharing this.
What’s are the advantage of using a docker container for openvpn, versus making the entire server an openvpn server?
Nice guide. It would be nice to clarify you need a 64 bits droplet for this :)
I get FATA[0000] Error response from daemon: container --rm not found, impossible to mount its volumes
when I try to create client certificates?
Very concise and easy to follow even for a newbie like me. However, when I attempt to connect my client, the connection fails and this is what is recorded in the client log:
Feb 25 21:07:00: Viscosity Mac 1.5.3 (1255) Feb 25 21:07:00: Viscosity OpenVPN Engine Started Feb 25 21:07:00: Running on Mac OS X 10.10.2 Feb 25 21:07:00: --------- Feb 25 21:07:00: Checking reachability status of connection… Feb 25 21:07:00: Connection is reachable. Starting connection attempt.
That’s it. Not very helpful output. Any idea what’s wrong? This is the output from ifconfig:
docker0 Link encap:Ethernet HWaddr aa:aa:aa:aa:aa:aa inet addr:172.xxx.xxx.xxx Bcast:0.0.0.0 Mask:255.xxx.xxx.xxx inet6 addr: xxxxxxxxxxxxxxxxxxxxxxxxxxx Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8 errors:0 dropped:0 overruns:0 frame:0 TX packets:8 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:536 (536.0 B) TX bytes:648 (648.0 B)
eth0 Link encap:Ethernet HWaddr aa:aa:aa:aa:aa:aa inet addr:178.xx.xxx.xxx Bcast:178.xxx.xxx.xxx Mask:255.xxx.xxx.xxx inet6 addr: xxxxxxxxxxxxxxxxxxxxxxxxxxx Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1308 errors:0 dropped:0 overruns:0 frame:0 TX packets:1262 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:106696 (106.6 KB) TX bytes:90915 (90.9 KB)
The latest attempt produced this:
Feb 25 21:52:04: Viscosity Mac 1.5.3 (1255) Feb 25 21:52:04: Viscosity OpenVPN Engine Started Feb 25 21:52:04: Running on Mac OS X 10.10.2 Feb 25 21:52:04: --------- Feb 25 21:52:04: Checking reachability status of connection… Feb 25 21:52:04: Connection is reachable. Starting connection attempt. Feb 25 21:52:05: Options error: --dh fails with ‘dh.key’: No such file or directory Feb 25 21:52:05: Options error: Please correct these errors.
Thank you for sharing this tutorial. Everything you mentioned worked fine for me. But while I am connected to my VPN via Tunnelblick and curl icanhazip.com
is returning the correct IP, I still get my personal IP when connected to my server through SSH. What am I missing here? How can I get the IP of the VPN?
Hi Kyle, thanks for putting this guide together. I had the vpn running flawlessly after following your guide but after trying to reconnect a few hours later am getting stuck at “waiting for a server response” when trying to connect.
I have restarted the machine, relaunched the process using docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_genconfig -u udp://vpn.example.com:1194
(with my domain sub’d in), and have verified the process is running using docker ps
.
Edit: after checking docker ps
again, it appears the process dies out shortly after starting.
Any suggestions? Thanks!
Prior to Step #5: Securely copying the certificates via SSH/SCP
I’m new to docker; how would I copy the openvpn certificates generated on docker to another computer via SSH/SCP? Still not entirely sure how to interact with the docker shell. although I did find a variety of syntax answers atstack overflow… Anyone?
I used this guide but windows clients couldn’t connect. There is a fork of ‘kylemanna/openvpn’ that works with Windows clients here: https://registry.hub.docker.com/u/nightling/openvpn/ (follow the steps after installing Docker).
This comment has been deleted
Hmmm… How can I generate separate certifcate, keys and config for the client instead of combined in .ovpn file?
There is a separated option for ovpn_getclient
. Brief documentation @ https://github.com/kylemanna/docker-openvpn/blob/master/docs/clients.md .
Basically, run something like ovpn_getclient CLIENT_NAME separated
Hi,
Nice tutorial, works perfectly. However, I was wondering how one could manage client certificate ie: revocation with this container?
I have tried several ways, can’t get it to work.
Just updated it to support this. Details at issue #38 and documentation.
You’ll need to do the following to update your docker image, OpenVPN config to support the feature:
docker pull kylemanna/openvpn
docker run --volumes-from $OVPN_DATA --rm kylemanna/openvpn ovpn_genconfig
Actual revocation:
docker run --rm -it --volumes-from $OVPN_DATA kylemanna/openvpn easyrsa revoke client1
docker run --rm -it --volumes-from $OVPN_DATA kylemanna/openvpn easyrsa gen-crl
I’m using a Windows machine to connect, but I receive the following error:
Tue May 19 15:16:19 2015 Authenticate/Decrypt packet error: bad packet ID (may be a replay): [ #62 / time = (1432041377) Tue May 19 15:16:17 2015 ] -- see the man page entry for --no-replay and --replay-window for more info or silence this warning with --mute-replay-warnings
Tue May 19 15:16:19 2015 TLS Error: incoming packet authentication failed from [AF_INET]x.x.x.x:1194
Is it because the opvn file has been combined with multiple keys and configs?
Thanks in advance.
I’m having a real strange issue. I set this up as instructed, connect fine using TunnelBlick, but if I reboot the droplet, the next I connect, I’m getting no connectivity to the internet. My IP isn’t changing, my traffic is stopping at the remote machine.
I’ve checked the logs, they don’t say anything to indicate why this may be.
Anyone got any ideas?
I’ve tried to recreate the entire thing from scratch but it still doesn’t work. I’ve even installed TunnelBlick on a fresh MacBook and used the same .ovpn file, and that can’t connect either.
Something weird is happening and I’m not sure where to look…
Hi, Awesome tutorial. I have a question:
Is there a way to configure the server to listen on port 443/tcp and 1194/udp as in jpetazzo/openvpn
Is there a similar set up in your in your image?
Thanks
Can you please let me know if there is a possibility to set static internal IP address for one of my devices connected to Docker OpenVPN?
Thanks in advance
curl https://get.docker.io/gpg | sudo apt-key add -
Isn’t working. Works with -L though:
curl -L https://get.docker.io/gpg | sudo apt-key add -
I get
gpg: no valid OpenPGP data found.
when trying to run
curl https://get.docker.io/gpg | sudo apt-key add -
I’m a total n00b, and I’m using a Ubuntu 15.04 droplet. In 15.04, Ubuntu moved away from Upstart to systemd. Consequently, the script in Step 3 may not be suitable for my OS.
If possible, could someone please point me in the right direction to auto-run the OpenVPN container with systemd. Thanks so much!!
The server works great, thanks!
Anyone know how to get this working with the VPN configuration GUI in Ubuntu 14.04 LTS? I believe it is called “NetworkManager”. I tried several different ways to set it up, but my client refuses to connect.
I can connect using openvpn from the command line.
I can’t find the generated .ovpn files. Am I missing something? I even did a find / -iname ‘*.ovpn’
This is good, but typically you should use the same image for both the data container and the container hosting the processes. This saves disk space - no need to add a busybox image to your system - and allows you to properly set permissions and potentially seed the data container with files if you need to. I would suggest creating the data container like this:
docker run --name $OVPN_DATA -v /etc/openvpn kylemanna/openvpn
Very useful!!! I installed OpenVPN according to the article and it worked properly.
Can the initial of the CA (ovpn_initpki) command run without the interaction to include the passphrase and common name. I believe the user will be prompted four times and run it excluding the -it parameter for non-interactive. Thanks.
Hi, Awesome tutorial. I have a question:
Is there a way to configure the server to listen on port 443/tcp and 1194/udp as in jpetazzo/openvpn
Is there a similar set up in your in your image?
Thanks
Can you please let me know if there is a possibility to set static internal IP address for one of my devices connected to Docker OpenVPN?
Thanks in advance
curl https://get.docker.io/gpg | sudo apt-key add -
Isn’t working. Works with -L though:
curl -L https://get.docker.io/gpg | sudo apt-key add -
I get
gpg: no valid OpenPGP data found.
when trying to run
curl https://get.docker.io/gpg | sudo apt-key add -
I’m a total n00b, and I’m using a Ubuntu 15.04 droplet. In 15.04, Ubuntu moved away from Upstart to systemd. Consequently, the script in Step 3 may not be suitable for my OS.
If possible, could someone please point me in the right direction to auto-run the OpenVPN container with systemd. Thanks so much!!
The server works great, thanks!
Anyone know how to get this working with the VPN configuration GUI in Ubuntu 14.04 LTS? I believe it is called “NetworkManager”. I tried several different ways to set it up, but my client refuses to connect.
I can connect using openvpn from the command line.
I can’t find the generated .ovpn files. Am I missing something? I even did a find / -iname ‘*.ovpn’
This is good, but typically you should use the same image for both the data container and the container hosting the processes. This saves disk space - no need to add a busybox image to your system - and allows you to properly set permissions and potentially seed the data container with files if you need to. I would suggest creating the data container like this:
docker run --name $OVPN_DATA -v /etc/openvpn kylemanna/openvpn
Very useful!!! I installed OpenVPN according to the article and it worked properly.
Can the initial of the CA (ovpn_initpki) command run without the interaction to include the passphrase and common name. I believe the user will be prompted four times and run it excluding the -it parameter for non-interactive. Thanks.
Thanks for your work. It works very well.
I followed exactly your tutorial, and it worked like a charm!
Do you know how I could disable route push? All my traffic is redirected through the openvpn server and I can’t find the config that causes it.
Thanks!
Thanks, great tutorial, however I can’t the .ovpn config file :D there is no directory when I run the command:
cat /etc/openvpn
and when I run the command
whereis openvpn
there is no output. Any help would be great, Thanks EDIT: oh I almost forgot, I don’t have Fully Qualified Domain Name, so I put my IP address there. EDIT2: My bad, it was in the ~ directory, after I have successfully connected to the OpenVPN I have something interesting encountered, Using Docker Method, a connection will be much faster established than a Normal OpenVPN setup, I wonder why is that?! (even the logs on the OpenVPN client are much less than Normal OpenVPN logs!)
Thanks. I did this with 16.04 except to install docker I followed https://docs.docker.com/engine/quickstart/
It works. First time. Which is a minor miracle to me.
If something goes wrong and you need to clean up files on the docker instance, you can connect with:
docker run --volumes-from $OVPN_DATA --rm -it kylemanna/openvpn /bin/bash
On 16.04 it seems that the script and tip to get it to start at machine boot don’t work (no more upstart, maybe?) How do you do that/.
Great article, very well done, clear and efficient!!! Really appreciate your work, thanks for sharing!
Hi,
This is great, I am getting these issues trying to connect… To confirm do I need to set a port forward and IP address for the docker container ?
My connection just stays in a ‘connecting’ state. Error below.
Jul 09 20:48:45: Viscosity Mac 1.6.4 (1348) Jul 09 20:48:45: Viscosity OpenVPN Engine Started Jul 09 20:48:45: Running on Mac OS X 10.11.5 Jul 09 20:48:45: --------- Jul 09 20:48:45: Checking reachability status of connection… Jul 09 20:48:45: Connection is reachable. Starting connection attempt. Jul 09 20:48:46: OpenVPN 2.3.11 x86_64-apple-darwin [SSL (OpenSSL)] [LZO] [PKCS11] [MH] [IPv6] built on May 10 2016 Jul 09 20:48:46: library versions: OpenSSL 1.0.2h 3 May 2016, LZO 2.09 Jul 09 20:48:47: WARNING: No server certificate verification method has been enabled. See http://openvpn.net/howto.html#mitm for more info. Jul 09 20:48:47: Control Channel Authentication: using ‘/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/connection.kLxxzU/ta.key’ as a OpenVPN static key file Jul 09 20:48:47: UDPv4 link local: [undef] Jul 09 20:48:47: UDPv4 link remote: [AF_INET]81.111.142.183:1194
Thanks,
Lee
Hi,
Great guide, however I am getting the below error :(
ul 11 17:03:49: Viscosity Mac 1.6.4 (1348) Jul 11 17:03:49: Viscosity OpenVPN Engine Started Jul 11 17:03:49: Running on Mac OS X 10.11.5 Jul 11 17:03:49: --------- Jul 11 17:03:49: Checking reachability status of connection… Jul 11 17:03:50: Connection is reachable. Starting connection attempt. Jul 11 17:03:50: OpenVPN 2.3.11 x86_64-apple-darwin [SSL (OpenSSL)] [LZO] [PKCS11] [MH] [IPv6] built on May 10 2016 Jul 11 17:03:50: library versions: OpenSSL 1.0.2h 3 May 2016, LZO 2.09 Jul 11 17:03:51: WARNING: No server certificate verification method has been enabled. See http://openvpn.net/howto.html#mitm for more info. Jul 11 17:03:51: Control Channel Authentication: using ‘/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/connection.ryjFhD/ta.key’ as a OpenVPN static key file Jul 11 17:03:51: UDPv4 link local: [undef] Jul 11 17:03:51: UDPv4 link remote: [AF_INET]x.x.x.x:1194 Jul 11 17:04:51: TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity) Jul 11 17:04:51: TLS Error: TLS handshake failed Jul 11 17:04:51: SIGUSR1[soft,tls-error] received, process restarting Jul 11 17:04:51: WARNING: No server certificate verification method has been enabled. See http://openvpn.net/howto.html#mitm for more info. Jul 11 17:04:51: Control Channel Authentication: using ‘/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/connection.ryjFhD/ta.key’ as a OpenVPN static key file Jul 11 17:04:51: UDPv4 link local: [undef] Jul 11 17:04:51: UDPv4 link remote: [AF_INET]x.x.x.x:1194 Jul 11 17:05:21: SIGTERM[hard,] received, process exiting
Many thanks for your instructions. I’m planning to do just this so I can use the VPN when I connect devices (Android phone, Chrome device, Linux laptop …) when using unsecured networks. I’ve been doing some stuff with Docker at work - nearly enough to be dangerous - so I should be able to follow your instructions. I do have one question though. Is it possible to build and test the Docker images on my home LAN and then copy them too a cloud server (using ‘docker save’/‘docker load’)
On my home LAN I have to generate new keys for SSH if I ever reinstall the OS (Linux) on one of my PCs. I would expect TLS to be just as sensitive but perhaps using a container shields me from that. I suppose at worse I need to regenerate keys once the move is complete.
Thanks!
I recently followed these instructions, and ran into trouble with the upstart section, since ubuntu now uses systemd by default. I hadn’t used systemd before, so I figured I would share what I did to use systemd instead.
First, I created the file /lib/systemd/system/docker-openvpn.service
with the following contents:
[Unit]
Description=Docker container for OpenVPN server
After=docker.service
[Service]
ExecStart=/usr/bin/docker run --volumes-from ovpn-data --rm -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
[Install]
WantedBy=multi-user.target
Then I ran sudo systemctl enable docker-openvpn.service
to enable the service at boot.
Let me know if you have any trouble with this!
Having troubles with upstart/init what resulted in a search to find out this is replaced by systemd? Can’t remember the exact steps i took to force the use of init but it resulted in an unbootable hostsystem which was luckily a testing machine. I followed these steps: https://www.nesono.com/node/368 and placed the script in /etc/init/
When i boot up the host it shows an ioremaperror.
For MAC OS X users (if not for Windows, etc users): You might need to do 2 additional steps that is not mentioned here:
Lot of thanks to the Kyle Manna for the wonderful work and to all the contributors!
I searched the comments, but I didn’t see anything about this… so I’m on 16.04, and I’m not able to reach the Internet as a client connected to the VPN, though it does work and I can access the host (i.e. I can ssh in to that droplet while connected to the VPN). I see that the docker container bypasses ufw, and it looks like everything needed as far as forwarding the DNS server, etc. to the client is working properly. I’m thinking maybe it’s some slight change from 14.04 to 16.04, but I have no idea. I know without docker, running the open vpn server directly, I would have to make changes (I forget exactly what they were, I think one was forwarding all requests with a setting that has “MASQUERADE” in it, but docker would bypass that/ip tables yeah?).
Any ideas?
Hello, the section on Arch Linux instructions seems to be outdated.
sudo install -o root -m 400 CLIENTNAME.ovpn /etc/openvpn/CLIENTNAME.conf
should be
sudo install -o root -m 400 CLIENTNAME.ovpn /etc/openvpn/**client/**CLIENTNAME.conf
That is, client/
should be inserted in the destination path.
Likewise,
systemctl start openvpn**-client**@CLIENTNAME
and
systemctl enable openvpn**-client**@CLIENTNAME
I got to the part where you are to run the command “sudo start docker-openvpn” but I get the following message:
sudo: start: command not found
Any idea what might be causing this?
This is a great tutorial. What about doing a new version with docker cloud integration?
For anyone following this guide that is using systemd instead of upstart, here is the content of
/etc/systemd/system/docker-openvpn.service
[Unit]
Description=Docker container for OpenVPN server"
[Service]
ExecStart=/usr/bin/docker run --volumes-from ovpn-data --rm -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
Restart=always
[Install]
WantedBy=multi-user.target
dont forget chmod +x
I have followed the procedure to deploy this. Everything looks fine and the docker container is running. however, I cannot telnet to the port 1194 after the setup. Do I need disable the iptables service?
I found my iptables are on. But from the print of iptables, I don’t see any traffic was defined “accept” or “declined” in the iptables.
could anyone here help me with it?
root@ip-10-10-11-110:/home/ubuntu# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9f0b7b66cd4d kylemanna/openvpn “ovpn_run” 2 seconds ago Up 1 seconds 0.0.0.0:1194->1194/udp admiring_brown
root@ip-10-10-11-110:/home/ubuntu# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp – anywhere anywhere tcp dpt:domain /* managed by lxd-bridge / ACCEPT udp – anywhere anywhere udp dpt:domain / managed by lxd-bridge / ACCEPT udp – anywhere anywhere udp dpt:bootps / managed by lxd-bridge */ ACCEPT udp – anywhere anywhere udp dpt:openvpn
Chain FORWARD (policy ACCEPT) target prot opt source destination ACCEPT all – anywhere anywhere /* managed by lxd-bridge / ACCEPT all – anywhere anywhere / managed by lxd-bridge */ DOCKER all – anywhere anywhere ACCEPT all – anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all – anywhere anywhere ACCEPT all – anywhere anywhere
Chain OUTPUT (policy ACCEPT) target prot opt source destination
Chain DOCKER (1 references) target prot opt source destination ACCEPT udp – anywhere ip-172-17-0-2.ec2.internal udp dpt:openvpn root@ip-10-10-11-110:/home/ubuntu#
Instead of upstart you can use docker restart policy, like this
docker run --volumes-from ovpn-data -d --restart unless-stopped -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
More on this here: https://docs.docker.com/config/containers/start-containers-automatically/
The command
sudo start docker-openvpn
causes sudo: start: command not found
.
I tried to run this:
sudo systemctl start docker-openvpn
and it didn’t work either - Failed to start docker-openvpn.service: Unit docker-openvpn.service not found.
Am I doing something wrong?
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.