我有以下docker-compose,moduleA如何找到moduleB正在运行的IP或端口,以便可以对其进行REST调用。
问题是我应该如何配置docker属性,使moduleA获得ModuleB的ip端口
version: "3"
services:
moduleA:
image: jboss/wildfly
ports:
- 9080:8080
- 9990:9990
- 65193:65193
volumes:
- ./ModuleA/target/ModuleA.war:/opt/jboss/wildfly/standalone/deployments/ModuleA.war
environment:
- MONGO_HOST=mongo
- MONGO_PORT=27017
- MONGO_USERNAME=myuser
- MONGO_PASSWORD=mypass
- MONGO_DATABASE=mydb
- MONGO_AUTHDB=admin
command: >
bash -c "/opt/jboss/wildfly/bin/add-user.sh admin Admin#007 --silent && /opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0"
links:
- mongo
depends_on:
- mongo
moduleb:
image: jboss/wildfly
ports:
- 9081:8080
- 9991:9990
- 65194:65193
volumes:
- ./ModuleB/target/ModuleB.war:/opt/jboss/wildfly/standalone/deployments/ModuleB.war
environment:
- MONGO_HOST=mongo
- MONGO_PORT=27017
- MONGO_USERNAME=myuser
- MONGO_PASSWORD=mypass
- MONGO_DATABASE=mydb
command: >
bash -c "/opt/jboss/wildfly/bin/add-user.sh admin Admin#007 --silent && /opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0"
links:
- mongo
depends_on:
- mongo
mongo:
image: mongo:4.0.10
container_name: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=mongouser
- MONGO_INITDB_ROOT_PASSWORD=mongopass
ports:
- 27017:27017
- 27018:27018
- 27019:27019
我已经对端口进行了硬编码,我们应该注入硬编码的端口还是它如何工作?
最佳答案
您可以按照与moduleA
相同的方式以moduleB
链接mongo
。然后在您的环境中使用相同的名称定义MODULEA_HOST
或在属性文件中使用。
关于java - docker-compose中的容器发现,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57311867/