1,问题:
在docker-compose.yml中定义了一个cerebro服务,指定了下面的网络

  services:
   cerebro:
	image: lmenezes/cerebro:0.8.3
 	container_name: cerebro
	ports:
  	- "9000:9000"
	command: 
  	- -Dhosts.0.host=http://elasticsearch:9200
	networks: 
  	- es7net

执行docker-compose up之后,报下面的错误

[root@localhost compose-elastic]# docker-compose up
ERROR: Service "cerebro" uses an undefined network "es7net"

2, 对应:
(1)解决方案1:生成一个网络,在docker-compose.yml中声明并将容器加入到该网络
用docker生成一个网络

[root@localhost compose-elastic]# docker network create --driver bridge es7net
2e8afa08b4e0ebd04fc8bc94082f28b8...
[root@localhost compose-elastic]# docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
2e8afa08b4e0        es7net              bridge              local

在docker-compose.yml中加入外部的网络声明
参考https://docs.docker.com/compose/compose-file/compose-file-v2/#network-configuration-reference
在这里插入图片描述

加入下面的外部网络声明

networks:
 es7net:
	external: true

(2) 解决方案2:在docker-compose.yml中声明一个网络,执行docker-compose up的时候生成

services:
  cerebro:
	image: lmenezes/cerebro:0.8.3
 	container_name: cerebro
	ports:
  	- "9000:9000"
	command: 
  	- -Dhosts.0.host=http://elasticsearch:9200
	networks:
  	- es7net     (声明容器的网络)
networks:
	es7net:
		driver: bridge  (声明要生成的网络)
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐