Docker Compose multiple networks

I have a couple of containers that I’m using that are using macvlan so I can give them a static IP address on the network. I would also like them to be able to use the default bridge to talk internally to other containers. Right now I have to manually add the bridge (system) network to the container because I can’t figure out how to use it in docker-compose.

Example:
#creating macvlan: docker network create -d macvlan -o parent=eth0 --subnet=192.168.1.0/24 --gateway=192.168.1.1 --ip-range 192.168.1.0/24 macvlan

version: '3'
services:
  name:
    image: img
    container_name: Name
    restart: unless-stopped
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - data:/data
    networks:
      macvlan:
        ipv4_address: 192.168.1.40
      bridge:
		
networks:
  macvlan:
    external: true
  bridge:
    external: true

volumes:
  data:
    external: true

In the example the macvlan works perfectly, I use this same external macvlan for several containers. The bridge section doesn’t work and gives me an error: “network–scoped alias is supported only for containers in user defined networks”. While I understand that I would like to figure out how to get the default 172.17.0.0/16 network added to this docker like it is on other dockers so that I can have the containers internally talk.

Thanks

I don’t know if you can connect to the default bridge, because that bridge is special, but if you just want a local IP address coming from Docker, you can use “default” instead of “bridge”. It means you will use the “default” network that Docker Compose would create for your compose project. If you don’t refer to that network when you override the network settings of a container, the default network will not be created. If you refer to that network, you don’t need to define it because it will exist automatically.

IT should work:

version: '3'
services:
  name:
    image: img
    container_name: Name
    restart: unless-stopped
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - data:/data
    networks:
      macvlan:
        ipv4_address: 192.168.1.40
      default:
		
networks:
  macvlan:
    external: true

volumes:
  data:
    external: true

Thank you for this ides, when I run that it creates a service_default that has a 172.19 address and not the 172.17 address to communicate with the other containers.

If you want to be able access containers attached to the default bridge, you can attach those containers to your user-defined bridge. If you create an external user-defined bridge as you did with the macvlan, you can attach that network to any container and you can use that in the compose file.