Is there a way to create compose networks without docker assigning IP addresses?

I have a containerised application that runs on a fairly customised network setup on an embedded platform. The container expects to manage IP networking on one of its interfaces and runs a dnsmasq instance internally to answer DHCP and DNS requests and sets up routing between that interface and another one.

I’d like to test this away from the embedded platform where I can’t run the customised docker environment. I’d like to run it up in a docker-compose stack with a compose network defined for the interface the container should be managing. But I can’t for the life of me figure out how to stop docker from doing IPAM on that network. All it needs to do is to create a network and attach containers to it with no IPAM but docker insists on allocating IP addresses to the interfaces inside the container.

I’ve even gone and implemented a custom network driver plugin that creates the veth pairs and doesn’t assign any IP addresses but docker/libnetwork still assigns the IP addresses.

Is there any way of doing what I want here using the built-in facilities of docker compose? Or am I stuck using something like pipework to configure the networking once the stack is up?

You are probably looking for this, but I could not make it work with compose:

https://docs.docker.com/engine/network/drivers/bridge/?uuid=391347cd-c885-4d4d-8acf-9dc02eb4b931#skip-bridge-ip-address-configuration

I didn’t know about it until today when I searched for a solution. First it didn’t seemt o work, because even with that label on the network, I still saw an IP address in the network definition and also saw the IP when running ip addr in the container, but then I tried removing the routing like

ip route del 172.19.0.0/16

Once it deleted the route, ip addr could not see the ip address. When I used another bridge network without the option I linked, deleting the route didn’t remove the IP from the output of ip addr.

Unfortunately, when I tried the same with Docker Compose, it didn’t work. First I used the “default” network:

services:
  test:
    image: nicolaka/netshoot
    command:
      - sleep
      - inf
    init: true
    privileged: true

networks:
  default:
    driver_opts:
      com.docker.network.bridge.inhibit_ipv4: "true"

But that completely ignored the option and the network got even IPv6 addresses. Then I tried to change the network name:

services:
  test:
    image: nicolaka/netshoot
    command:
      - sleep
      - inf
    init: true
    privileged: true
    networks:
      - noip

networks:
  noip:
    driver_opts:
      com.docker.network.bridge.inhibit_ipv4: "true"

It looke right, but deleting the route didn’t delete the IP from the interface. So looks like Docker Compose uses the metadata from the network interface and do something with the IP that makes it different.

I even tried extrnal docker network which worked with docker run, but not with compose.

update:

I updated Docker and compose and now I can’t reproduce the behavior even without Compose.

Is this solved in docker 27.5.1? i’m facing similar problem in 27.5.0.

The version you mentioned came out in January this year. This topic is two weeks old. I thought you wanted to write 28.5, but the latest Docker CE version is 28.4.0. Are you using a Docker built directly from source code?

update: Okay, I found your new topic.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.