假设我有两个按如下方式缩放的 Web 容器:
docker-compose scale web=2
Web 容器执行如下(来自 Dockerfile):
ENTRYPOINT [ "java", "-jar", "/app/my-jar-server-1.0.jar" ]
确保两个不同的嵌入式 tomcat 侦听不同端口的最佳策略是什么(例如,如果我想构建类似 Heroku 的基础设施:请参阅 foreman)?
换句话说,两个容器都将监听同一个端口,从而导致冲突。
理想情况下,我需要对两个 tomcat 实例进行循环请求。我正在寻找工具和想法...
编辑1:
这是我尝试过的:
来自 docker-compose.yml:
loadbalancer:
image: haproxy
links:
- web
ports:
- "8080:8080"
web:
build: ./web
来自 ./web/Dockerfile:
FROM java:8
ADD ./bignibou-server-1.0.jar /app/bignibou-server-1.0.jar
ADD ./spring-cloud.properties /app/spring-cloud.properties
ENV SPRING_CLOUD_PROPERTIESFILE=/app/spring-cloud.properties
ENV SPRING_PROFILES_ACTIVE=cloud
ENV SPRING_CLOUD_APP_NAME=bignibou
ENV CLEARDB_DATABASE_URL=mysql://root:root@localhost:3306/bignibou_dev
ENV REDISCLOUD_URL=redis://dummy:dummy@localhost:6379
ENV DYNO=dummy
EXPOSE 8080
ENTRYPOINT [ "java", "-jar", "/app/bignibou-server-1.0.jar" ]
这是我得到的:
loadbalancer_1 | [ALERT] 091/105717 (1) : Could not open configuration file /usr/local/etc/haproxy/haproxy.cfg : No such file or directory
dockertests_loadbalancer_1 exited with code 1
Gracefully stopping... (press Ctrl+C again to force)
Stopping dockertests_web_1...
Exception in thread Thread-1 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
File "/code/build/docker-compose/out00-PYZ.pyz/threading", line 552, in __bootstrap_inner
File "/code/build/docker-compose/out00-PYZ.pyz/threading", line 505, in run
File "/code/build/docker-compose/out00-PYZ.pyz/compose.cli.multiplexer", line 41, in _enqueue_output
File "/code/build/docker-compose/out00-PYZ.pyz/compose.cli.log_printer", line 62, in _make_log_generator
File "/code/build/docker-compose/out00-PYZ.pyz/compose.container", line 139, in wait
File "/code/build/docker-compose/out00-PYZ.pyz/docker.client", line 999, in wait
File "/code/build/docker-compose/out00-PYZ.pyz/docker.client", line 78, in _post
File "/code/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 425, in post
File "/code/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 383, in request
File "/code/build/docker-compose/out00-PYZ.pyz/requests.sessions", line 486, in send
File "/code/build/docker-compose/out00-PYZ.pyz/requests.adapters", line 374, in send
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'error'
编辑 2:忽略我的编辑 1,我无法重现该问题。
但是,我能够在 tomcat 上成功启动两个实例,但我尝试通过浏览器访问它们:
http://172.17.42.1:8080/
无济于事。有人可以帮忙吗?