Skip to content

Instantly share code, notes, and snippets.

@arcturus011
Forked from ptflp/README.md
Last active September 13, 2021 03:55
Show Gist options
  • Save arcturus011/ec190e11f2e5d8b528c764de47ebe4cf to your computer and use it in GitHub Desktop.
Save arcturus011/ec190e11f2e5d8b528c764de47ebe4cf to your computer and use it in GitHub Desktop.
docker tun device into container

Docker tun device into container install openvpn or other soft, which uses tun devices

version: "3"
services:
rsync_server:
container_name: openvpn
image: 'myopenvpn'
environment:
TZ: "Asia/Shanghai"
cap_add:
- NET_ADMIN
restart: always
devices:
- "/dev/net/tun"
volumes:
- $PWD/pi3.ovpn:/etc/openvpn/openvpn.conf
- $PWD/start_vpn.sh:/bin/start_vpn.sh
command: >
bash -c "echo '开始 openvpn';
iptables -o eth0 -t nat -I POSTROUTING -j MASQUERADE;
openvpn --config /etc/openvpn/openvpn.conf"
docker run -d --name tundevica \
--cap-add=NET_ADMIN \
--device /dev/net/tun \
ubuntu tail -f /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment