🔒 Setup Gluetun — Route Any Container Through a VPN
Deploy Gluetun on Ubuntu with Docker — a lightweight VPN client container that connects to your commercial VPN provider and lets you route any other container's traffic through the tunnel, with a control API on port 8223.
📦 Resources & Setup Scripts
Grab the automated bash script from GitHub to follow along with the video.
Quick Install:
wget https://raw.githubusercontent.com/mhmdali94/Docker/main/vpn/gluetun/gluetun-ubuntu.sh
chmod +x gluetun-ubuntu.sh
sudo bash gluetun-ubuntu.sh
Tutorial Steps
1 Download the Script
wget https://raw.githubusercontent.com/mhmdali94/Docker/main/vpn/gluetun/gluetun-ubuntu.sh
2 Make it Executable
chmod +x gluetun-ubuntu.sh
3 Run the Installer
The script installs Docker if needed and starts Gluetun with the NET_ADMIN capability and the tun device it needs to build a tunnel. You supply your VPN provider and OpenVPN credentials via environment variables; the control API listens on port 8223.
sudo bash gluetun-ubuntu.sh
4 Verify the Tunnel and Route a Container
Check the logs to confirm the VPN connected and see the public IP, then point another container at Gluetun with network_mode so its traffic goes through the tunnel:
docker logs gluetun | grep -i "public ip"
Ports Used
| Port | Purpose |
|---|---|
| 8223 | Control API (host → container 8000) — status and public IP |
| NET_ADMIN + tun | Required to build the VPN tunnel — grant only here |
| network_mode | Route others with container:gluetun; publish their ports on Gluetun |
| kill switch | Blocks traffic if the tunnel drops — no IP leak |