Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static IP address doesn't work in docker compose v3

Tags:

docker

swarm

From the official document, the static ip address should work with docker compose v3 + docker swarm. But I cannot make it work.

This is my docker compose yaml:

version: '3'

networks:
test:
    ipam:
    driver: default
    config:
        - subnet: 10.1.0.0/24

services:
one:
    image: mongo
    networks:
    test:
        ipv4_address: '10.1.0.100'

two:
    image: mongo
    networks:
    test:
        ipv4_address: '10.1.0.101'
three:
    image: mongo
    networks:
    test:
        ipv4_address: '10.1.0.102'

I use docker stack up -c xxx.yml test to deploy. I found the ip of the created containers are 10.1.0.3, 10.1.0.5, ...

like image 763
PunCha Avatar asked Jul 19 '17 04:07

PunCha


People also ask

Can a docker container have a static IP?

Static IP addresses don't change when containers or services are stopped and started, making them useful for permanent networking. Assigning Docker containers static IP addresses is an easy way to make them more accessible.

What IP address does a docker container use?

By default, the container is assigned an IP address for every Docker network it connects to. And each network is created with a default subnet mask, using it as a pool later on to give away the IP addresses. Usually Docker uses the default 172.17. 0.0/16 subnet for container networking.

What is docker0 IP address?

The default IP range for the docker0 network is 172.17. 0.0/16.


1 Answers

That works in non-swarm mode, but not in swarm mode. You may subscribe to this ticket to find out when/if support is added.

At the moment, there's an anecdotal claim of a workaround, but nobody else seems to have corroborated it.

like image 123
Jamie Jackson Avatar answered Oct 17 '22 16:10

Jamie Jackson