I want to run two docker containers in the same Linux network namespace.
My goal is to route all my torrent traffic through OpenVPN.
This script successfully creates a openvpn client container.
I can successfully enter this namespace and verify my IP address is indeed the OpenVPN IP address.
My issue is - How do I run the qbittorent docker container inside the openvpn network namespace?
Is there some sort of flag when starting a docker container to specify the network namespace to run in?
Any other possible solutions?
It is my understanding that I can not change the network namespace of a an already running process
Thanks
UPDATE
SOLUTION
add this
--net=container:$openvpn_client
openvpn_client="openvpn-client"
torrent_client="torrent_client"
dewinettorrent_ns="dewinettorrent_ns"
function getpid {
pid="$(docker inspect -f '{{.State.Pid}}' "$1")"
echo $pid
}
docker rm -f $openvpn_client
docker rm -f $torrent_client
ip netns delete $dewinettorrent
ip netns pids $dewinettorrent_ns | xargs -t kill -9
docker run -d \
--privileged \
--name=$openvpn_client \
--volume /home/dewi/code/dot-files/vpn/:/data/vpn \
--volume /home/dewi/code/dewi_projects/ivacy_vpn_auth:/data/vpn/auth-user-pass \
docker-openvpn-client-dewi
docker run -d \
--name=$torrent_client \
-e PUID=1000 \
-e PGID=1000 \
-e TZ=Europe/London \
-e WEBUI_PORT=8080 \
-p 9080:8080 \
-v /path/to/appdata/config:/config \
-v /path/to/downloads:/downloads \
lscr.io/linuxserver/qbittorrent
mkdir -p /var/run/netns;
ln -fs "/proc/$(getpid $openvpn_client)/ns/net" /var/run/netns/$dewinettorrent_ns
mkdir -p /etc/netns/$dewinettorrent_ns/
echo 'nameserver 8.8.8.8' > /etc/netns/$dewinettorrent_ns/resolv.conf
docker exec -i $openvpn_client bash /data/scripts/entry.sh &
ip netns exec $dewinettorrent_ns curl icanhazip.com #successfully returns back my VPN IP address