我创建2个spring boot应用程序。 ConnectToBd和ResourceCalculate
application.properties:
nsi.url=http://ip:port/odo/find/root/
bd_connect=http://ip:port/connect-to-bd/getdata?
Spring控制器:
@PropertySource("application.properties")
@RestController
public class ResourceCalculateCntr {
@Value("${nsi.url}")
private String nsi;
@Value("${bd_connect}")
private String connect;
@RequestMapping(value = "getProperties", method = RequestMethod.GET)
public String retProps() {
return nsi + " " + connect;
}
使用gradle构建
Dockerfile bdconnect并计算。示例:
FROM openjdk:8
EXROSE 8080
ADD resourceCalculate.war resourceCalculate.war
ENTRYPOINT ["java", "-jar", "resourceCalculate.war"]
docker build成功成功
然后我使用docker-compose:
version: '3'
services:
calc:
image: calculate
container_name: calc
ports:
- "2020:8080"
enviroment:
- bd_connect=connect
depend_on:
- connect
links:
- connect
networks:
- calc-net
connect:
image: dbconnect
container_name: connect
ports:
- "1010:8080"
networks:
- calc_net
networks:
calc_net:
driver: bridge
执行docker-compose up并编写:创建完成 然后我在容器中输入:'docker-compose exec calc sh'和'ping connect'一切正常 但是,如果我在浏览器中请求网络服务,则会看到响应:
http://ip:port/odo/find/root/ connect
为什么呢?