我想使用弹性的docker-elk,然后我克隆了弹性github代码。我想为每个容器使用一个特定的ip,所以我为每个容器定义一个特定的ip,当我运行docker-compose up
时,我遇到了错误
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.
它没有显示任何网络的子网,但是我定义了子网,docker-compose.yml
就像这样
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
和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
我刚遇到这个问题,我的问题似乎是docker如何缓存网络和容器的问题。我不得不docker network rm
以前创建的网络。我还需要docker ps -a
和docker rm
先前创建的容器,因为它们被缓存以使用您将要删除的网络。删除所有剩余的工件后,它正确启动。
根据Compose docs,ipam
块必须定义子网范围和网关。所以只需将您更新为:
ipam:
config:
- driver: default
subnet: 172.18.1.0/24
gateway: 172.18.1.1
除了使用docker network rm <networkname>
命令删除冲突的子网IP中的网络。确保在同一个docker compose文件的networks部分中指定的子网IP上仔细检查分配给docker compose文件中的服务的所有IP地址。当您的docker composer文件具有许多服务和网络时,很容易忽略IP。
错误的子网错误示例:“172.22.0.1:它不属于任何此网络的子网”。
version: '3'
services:
web_service:
networks:
webservices:
ipv4_address: 172.22.0.1
image: nginx:latest
environment:
- NGINX_HOST=web.phenex.docker
- NGINX_PORT=80
networks:
webservices:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.21.0.0/24