Compose: Compose fails to create dependent container for network_mode: container

Created on 15 Jun 2016  路  4Comments  路  Source: docker/compose

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!

Most helpful comment

I think you want service:openvpn-client, not container.

All 4 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

saulshanabrook picture saulshanabrook  路  3Comments

squeaky-pl picture squeaky-pl  路  3Comments

dazorni picture dazorni  路  3Comments

bitver picture bitver  路  3Comments

Hendrik-H picture Hendrik-H  路  3Comments