Docker compose networking - Priority property ignored

Viewed 272

I composed docker-compose.yaml file which contains 4 network interfaces, these interfaces needs to be in a specific order when mounted to the docker container.

Docker Engine Version: 19.03

Docker-compose Version: 2.4.1

we're using macvlan driver as part of our system in order to have L2 packets transfer between host interfaces. and the docker container we're using to host everything on is based on ubuntu:18.04

networks:
    sim1:
       name: sim1
       driver: macvlan
       driver_opts:
           parent: ens20
           macvlan_mode: bridge
       ipam:
           config:
           - subnet: 192.3.0.0/16
             ip_range: 192.3.1.0/24
    sim2:
       name: sim2
       driver: macvlan
       driver_opts:
           parent: ens21
           macvlan_mode: bridge
       ipam:
           config:
           - subnet: 192.4.0.0/16
             ip_range: 192.4.1.0/24
    sim3:
       name: sim1
       driver: macvlan
       driver_opts:
           parent: ens20
           macvlan_mode: bridge
       ipam:
           config:
           - subnet: 192.5.0.0/16
             ip_range: 192.5.1.0/24
    sim4:
       name: sim1
       driver: macvlan
       driver_opts:
           parent: ens20
           macvlan_mode: bridge
       ipam:
           config:
           - subnet: 192.6.0.0/16
             ip_range: 192.6.1.0/24

I saw that there's a property called: priority, this property allows to organize the network interfaces according to a metrics you specify on the compose.yaml file.

priority indicates in which order Compose implementation SHOULD connect the service’s containers to its networks. If unspecified, the default value is 0.

Docker-compose priority

When trying to apply this priority feature on the yaml file I'm getting no errors and no warnings, just ignored on the docker side, and when executing ifconfig I see that the interfaces got in a wrong order.

This is the output of the ifconfig (after filter the results)

eth0: sim1
eth1: sim4
eth2: sim3
eth3: sim2
services:
   app1:
       image: nginx:latest
       command: "tail -f /dev/null"
       networks:
          sim1:
              priority: 1000
          sim2:
              priority: 900
          sim3:
              priority: 800
          sim4:
              priority: 700

I've been searched the internet without any luck and saw that there's a lot of peoples who came across this without any luck.

Github Issue

1 Answers

The networks should be connected in alphabetical order. You can see a demonstration of this behavior in this gist. I think the problem is in your compose file. Under the networks: section you have:

sim3:
  name: sim1

and

sim4:
  name: sim1

Notice how both sim3 and sim4 have their name set as sim1.

If you make these all unique in the correct order and get rid of the priority settings then it should work as expected.

services:
  app1:
    image: nginx:latest
    command: "tail -f /dev/null"
    networks:
      - sim1
      - sim2
      - sim3
      - sim4

networks:
  sim1:
    name: sim1
    driver: macvlan
    driver_opts:
      parent: ens20
      macvlan_mode: bridge
    ipam:
      config:
        - subnet: 192.3.0.0/16
        ip_range: 192.3.1.0/24
  sim2:
    name: sim2
    driver: macvlan
    driver_opts:
      parent: ens21
      macvlan_mode: bridge
    ipam:
      config:
        - subnet: 192.4.0.0/16
        ip_range: 192.4.1.0/24
  sim3:
    name: sim3
    driver: macvlan
    driver_opts:
      parent: ens20
      macvlan_mode: bridge
    ipam:
      config:
        - subnet: 192.5.0.0/16
        ip_range: 192.5.1.0/24
  sim4:
    name: sim4
    driver: macvlan
    driver_opts:
      parent: ens20
      macvlan_mode: bridge
    ipam:
      config:
        - subnet: 192.6.0.0/16
        ip_range: 192.6.1.0/24
Related