我的docker-compose.yml
配置文件如下:
version: "2"
services:
spring-cloud-eureka-server01:
#image: java 指定镜像名或者 id,没有就会下载
image: leegoo0820/spring-cloud-eureka-server01-service:0.0.1-SNAPSHOT
volumes: #挂载目录
- "/usr/tmp/data/spring-cloud-eureka-server01"
container_name: spring-cloud-eureka-server_eureka01
build: .
ports: #开放端口
- "8761:8761"
#links:
# - spring-cloud-eureka-server02:discovery
#environment: 设置环境参数
# - spring.profile.active=dev
spring-cloud-eureka-server02:
#image: java 指定镜像名或者 id,没有就会下载
image: leegoo0820/spring-cloud-eureka-server02-service:0.0.1-SNAPSHOT
volumes: #挂载目录
- "/usr/tmp/data/spring-cloud-eureka-server02"
container_name: spring-cloud-eureka-server_eureka02
build: .
ports: #开放端口
- "8762:8762"
spring-cloud-eureka-client01:
#image: java 指定镜像名或者 id,没有就会下载
image: leegoo0820/spring-cloud-eureka-client01:0.0.1-SNAPSHOT
volumes: #挂载目录
- "/usr/tmp/data/spring-cloud-eureka-client01"
#container_name: spring-cloud-eureka-client01
build: .
ports: #开放端口
- "8846:8846"
我现在想水平扩容 spring-cloud-eureka-client01
节点到三个节点,
使用命令 docker-compose scale spring-cloud-eureka-client01=3
但是会报错,如下所示:
WARNING: The scale command is deprecated. Use the up command with the --scale flag instead.
WARNING: The "spring-cloud-eureka-client01" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.
Starting spring-cloud-eureka_spring-cloud-eureka-client01_1 ... done
Creating spring-cloud-eureka_spring-cloud-eureka-client01_2 ... error
Creating spring-cloud-eureka_spring-cloud-eureka-client01_3 ... error
ERROR: for spring-cloud-eureka_spring-cloud-eureka-client01_2 Cannot start service spring-cloud-eureka-client01: b'driver failed programming external connectivity on endpoint spring-cloud-eureka_spring-cloud-eureka-client01_2 (f820f286717a14e11745016963b76ab44622ef7895b1201130129ce1524a159c): Bind for 0.0.0.0:8846 failed: port is already allocated'
ERROR: for spring-cloud-eureka_spring-cloud-eureka-client01_3 Cannot start service spring-cloud-eureka-client01: b'driver failed programming external connectivity on endpoint spring-cloud-eureka_spring-cloud-eureka-client01_3 (7023830ee4f35fe85c75e2a70f276f73fec8ba949d1cfb641a3a19e12f849857): Bind for 0.0.0.0:8846 failed: port is already allocated'
ERROR: Cannot start service spring-cloud-eureka-client01: b'driver failed programming external connectivity on endpoint spring-cloud-eureka_spring-cloud-eureka-client01_2 (f820f286717a14e11745016963b76ab44622ef7895b1201130129ce1524a159c): Bind for 0.0.0.0:8846 failed: port is already allocated'
大概意思就是说扩容的后面几个节点都需要使用 8846 端口,但是 8846 端口已经被第一个占用了,那么我应该怎么样才能够进行扩容呢?
1
wangxiaoaer 2019-07-07 13:14:18 +08:00 via Android
再加一个负载均衡的 container,对外的端口由这个 container 影射,spring 的端口不要映射,由前面那个 container 转发。
可以搜索一下 nginx-proxy 这个 docker 镜像。 |
2
leegoo OP @wangxiaoaer 好,谢谢 。我试试
|
3
godsoul 2020-05-06 18:40:53 +08:00
你端口被占用了,你要水平扩容的端口暴露,这么写 "8761-8800:8761" 这样他会自动找可以用的端口暴露的。
|