Docker compose with static IP for external network

hello i try set static IP addrees for container for external network but receive error.

version: '3'

services:
  reverse-proxy:
    image: traefik:v2.5
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      my-dhcp-eth0-6d6da6:
        ipv4_address: 192.168.1.2
networks:
  default:
    external: true
    name: my-dhcp-eth0-6d6da6

error: ERROR: for c95a62577e09_traefik_reverse-proxy_1 user specified IP address is supported only when connecting to networks with user configured subnets ERROR: for reverse-proxy user specified IP address is supported only when connecting to networks with user configured subnets

Network already exists and work other container on it.

What is problem ?

My guess: It doesn’t work because you refer to your external network with the external name instead of the name you used under networks. Try this:

version: '3'

services:
  reverse-proxy:
    image: traefik:v2.5
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      default:
        ipv4_address: 192.168.1.2
networks:
  default:
    external: true
    name: my-dhcp-eth0-6d6da6

or this

version: '3'

services:
  reverse-proxy:
    image: traefik:v2.5
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      my-dhcp-eth0-6d6da6:
        ipv4_address: 192.168.1.2
networks:
  my-dhcp-eth0-6d6da6:
    external: true
    name: my-dhcp-eth0-6d6da6
1 Like

dont work no one variant. the same error

Please clearify what you mean by “external network”? I

External as in an existing docker bridge/overlay network with the default ip ranges docker provides?
External as in an existing docker network that is specified to “use the same ip range as your local lan”?

my-dhcp-eth0-6d6da6 is mavclan exists network which take dynamic ip from dhcp

That’s what I though. Please share the command you used to create the mavlan network, and the cidr or your local subnet.

docker network create -d macvlan 
  --subnet=192.168.1.0/24 
  --gateway=192.168.1.1 
  -o parent=eth0 my-dhcp-eth0-6d6da6

Hmm, odd error message.

I know that macvlan networks and ipv4_adddress can be use in docker-compose deployment - been there, done that. But I always configured --ip-range= to specify a range within my subnet that is not handled by dhcp.

there are docker or macvlan developers live on this forum? or should I write somewhere else on this issue ?

i post bug to docker team

“services:
reverse-proxy:
image: traefik:v2.5
ports:
- “80:80”
- “8080:8080”
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
my-dhcp-eth0-6d6da6:
ipv4_address: 192.168.1.2
networks:
my-dhcp-eth0-6d6da6:
external: true
name: my-dhcp-eth0-6d6da6”

I have been trying to make this work for a very long time and for some reason the simplicity in the way you coded this finally make it sink in and I am finally assigning addresses in my compose files. Outstanding. Thank you for this.