rancher / os

Tiny Linux distro that runs the entire OS as Docker containers
https://rancher.com/docs/os/v1.x/en/
Apache License 2.0
6.44k stars 655 forks source link

How to add a docker bridge network through config #2950

Open LaurensVanAcker opened 4 years ago

LaurensVanAcker commented 4 years ago

Hi

In my custom service, I can specify a network I created from Portainer using net: name123. But how do I create this bridge network from the config files?

I tried adding:

  networks:
    name123:
      driver: bridge

To the config.yml, but it's ignored. I also tried adding this to a custom service yml, but I getting a parse error:

grafana:
  container_name: grafana
  image: grafana/grafana
  net: name123
networks:
  name123:
    driver: bridge
LaurensVanAcker commented 4 years ago

Is it possible or not?

prupp commented 4 years ago

I'm interested in creating a custom bridge network as well. I tried it docker-compose style as @LaurensVanAcker did it in the post above, but without any luck.

I guess, rancher-compose doesn't support network configuration, right? How can we configure user defined bridge networks in rancher-compose and automatically attach containers to them? Couldn't find anything in the rancheros docs...

I need the custom bridge network mainly for container communication. I don't want to use the deprecated --link argument.

anselstetter commented 3 years ago

@prupp , @LaurensVanAcker

I know it's possible way too late, but I've had the same requirement for running caddy and forwarding the requests to to the specific container by name.

I use BurmillaOS, which is a fork of RancherOS, since RancherOS is EOL and does not work on the Pi 4.

I had to look in the source code of rancher-compose, because documentation for this use case is virtually non-existent.

To make it work you have to create a new network

docker network create web

and put all containers, which should communicate between each other in the same network with net:

image:
  image: image/image
  container_name: image 
  net: web

It seems that setting this via config is not supported, so you have to issue the docker command one time, or add it to cloud config, which might work also, but I have not tried this:

runcmd:
  - [ docker, network, create, web]