gpt4 book ai didi

heroku - 在类似Heroku的云中扩展Web容器时处理嵌入式tomcat端口号的问题

转载 作者:行者123 更新时间:2023-12-02 19:43:08 24 4
gpt4 key购买 nike

假设我有两个缩放比例如下的Web容器:

docker-compose scale web=2

Web容器执行如下(从Dockerfile中执行):
ENTRYPOINT [ "java", "-jar", "/app/my-jar-server-1.0.jar" ]

确保两个不同的嵌入式tomcat侦听不同端口的最佳策略是什么(例如,如果我要构建类似Heroku的基础架构: see 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'

edit 2 :忽略我的编辑1,我无法重现该问题。

但是,我能够在tomcat上成功启动两个实例,但尝试通过浏览器访问它们:
http://172.17.42.1:8080/

无济于事。有人可以帮忙吗?

最佳答案

最简单的方法(不沿领事路线走)是设置“loadbalancer”容器以了解您的“web”容器,例如:

web:
image: tomcat

loadbalancer:
image: haproxy
links:
- web
ports:
- "8080:8080"

请尝试docker-compose文档,特别是有关“链接”的部分: https://docs.docker.com/compose/yml/#links

关于heroku - 在类似Heroku的云中扩展Web容器时处理嵌入式tomcat端口号的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29317482/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com