docker-compose up error, Invalid address

I want to use elastic's docker-elk, then I cloned elastic github code. And I want to use a specific ip for every container, so I define a specific ip for every container, when I run docker-compose up, I meet the error

ERROR: for elasticsearch  Cannot start service elasticsearch: Invalid address 172.18.1.3: It does not belong to any of this network's subnets
ERROR: Encountered errors while bringing up the project.

it shows no any of network's subnet, but I define the subnet, and docker-compose.yml like this

version: '2'

services:

  elasticsearch:
    build: elasticsearch/      
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xmx256m -Xms256m"
    networks:
      elk:
        ipv4_address: 172.18.1.3

  logstash:
    build: logstash/
    ports:
      - "5000:5000"
    environment:
      LS_JAVA_OPTS: "-Xmx256m -Xms256m"
    networks:
      elk:
        ipv4_address: 172.18.1.4
    depends_on:
      - elasticsearch

  kibana:
    build: kibana/
    ports:
      - "5601:5601"
    networks:
      elk:
        ipv4_address: 172.18.1.5
    depends_on:
      - elasticsearch

networks:

  elk:
    driver: bridge
    ipam:
      config:
        - subnet: 172.18.1.0/24

and docker version

Client:
 Version:      17.06.0-ce
 API version:  1.30
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:20:36 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.06.0-ce
 API version:  1.30 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   02c1d87
 Built:        Fri Jun 23 21:21:56 2017
 OS/Arch:      linux/amd64
 Experimental: false

1 answer

  • answered 2017-08-13 03:56 ivan.sim

    According to the Compose docs, the ipam block must have subnet range and gateway defined. So just update yours to:

    ipam:
      config:        
        - driver: default
          subnet: 172.18.1.0/24
          gateway: 172.18.1.1