Hello,
I'm trying to have a docker compose with a container providing the connection to a VPN, and another container using that connection as the network_mode. Here's a minimal example:
services:
openvpn-client:
build: ./openvpn-client
image: nitnelave/openvpn-client
cap_add:
- NET_ADMIN
devices:
- "/dev/net/tun"
container_name: openvpn-client
rtorrent:
image: diameter/rtorrent-rutorrent:64
container_name: rtorrent
network_mode: "container:openvpn-client"
depends_on:
- openvpn-client
However, when I try to run docker-compose up
or create
, I get the following error:
ERROR: Service 'rtorrent' uses the network stack of container 'openvpn-client' which does not exist.
The problem is that it won't even pull the image if openvpn-client is not _running_, which makes no sense. Building the images shouldn't be a problem, for sure, and starting the images either, since I have the explicit dependency.
Any idea on how to make this work?
Thanks!
I think you want service:openvpn-client
, not container
.
Thanks, that's what I needed.
Maybe this part of the docker-compose documentation should be improved?
https://docs.docker.com/compose/compose-file/#network_mode
It is adding network_mode: "container:[container name/id]"
Can that notation still be used or it should be always network_mode: "service:[service name]" ?
I ran in the same problem and think that there should be a clear note in the docs that docker compose fails to create the dependent container when using network_mode: "container:[container name/id]"
but it does work when using network_mode: "service:[service name]"
.
Can someone add such a note?
Most helpful comment
I think you want
service:openvpn-client
, notcontainer
.