Docker Community Forums

Share and learn in the Docker community.

Overlay network with standalone containers, container restart when managers are unavailable

Hi!

We have some standalone containers (separate edge computers) utilizing the overlay network. These machines are connected with 4G connections, and will sometimes be without a internet connection.

Our issue arises when the edge machines reboots, as the containers will not start when the attachable overlay network is not available. (we need these containers to buffer data until the connection is valid again)

So I guess my question is this: Is there any way to force a start of standalone containers even though the overlay networks is not available?

Thank you for reading my post!

These three networks are built into Docker. When you run a container, you can use the --network flag to specify which networks your container should connect to.

The bridge network represents the docker0 network present in all Docker installations. Unless you specify otherwise with the docker run --network= option, the Docker daemon connects containers to this network by default. You can see this bridge as part of a host’s network stack by using the ip addr show command (or short form, ip a) on the host. (The ifconfig command is deprecated. It may also work or give you a command not found error, depending on your system.)

$ ip addr show

docker0 Link encap:Ethernet HWaddr 02:42:47:bc:3a:eb
inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:47ff:febc:3aeb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:9001 Metric:1
RX packets:17 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1100 (1.1 KB) TX bytes:648 (648.0 B)

are you a bot?

I am using --network flag.

My problem occurs when the network is not available when rebooting the machine. Meaning that when the container is trying to auto-start, it will not successfully start.

I don’t think thats possible but you could have a network-manager container, and remove the --network argument from your container. Your network-manager container will restart on boot and will constantly try to connect your container to your overlay network. If the network isn’t available the operation will fail and your network-manager can wait x seconds before retrying. If the overlay network is available again the network-manager will successfully connect your container to the overlay network and your container can do its work.

1 Like

This is a great tip, and might be my solution!

I allready have a script (close to finished) that can be run in the host OS, but it would be awesome to modifiy it into a separate network-manager container.

Can this be done with a normal alpine container, with privileged access? Do you have any tips for how the simplest network-manager container can be built/obtained, or how to run docker host commands inside a container?

Here is my startup script for my host OS(not finished/tested)

docker network disconnect myNetwork myContainer
docker start myContainer

while [ ! "$(docker network ls -f name=myNetwork )" ] ;
do
    echo 'Docker network myNetwork is not present, execute standalone container onboadring procedure';
    docker network connect myNetwork myContainer
done
    echo 'Docker network myNetwork is OK, noting to do but maybe log it to some logfile'

You can mount the docker socket into the container and install the CLI in the container or use the docker engine API to do your magic.
(Disclaimer: Not tested)

1 Like