[英]Unknown Host Exception
Unknown HostException Exception on Docker Container. Docker 容器上的未知 HostException 异常。
I have multiples services, my docker-compose has the following code:我有多个服务,我的 docker-compose 有以下代码:
version: '3.5'
services:
reservation:
container_name: sp-app-reservation
image: swimming-pool/reservation-service
environment:
- SPRING_PROFILES_ACTIVE=dev
ports:
- 8181:8182
depends_on:
- notification
network_mode: host
restart: always
web:
container_name: sp-app-web-ui
image: swimming-pool/web-ui-service
environment:
- SPRING_PROFILES_ACTIVE=dev
ports:
- 8080:8081
depends_on:
- notification
- reservation
- fileupload
network_mode: host
restart: always
eureka:
container_name: sp-app-eureka
image: swimming-pool/discovery-service
environment:
- SPRING_PROFILES_ACTIVE=dev
- SERVICE_PORT_RESERVATION=8181
- SERVICE_PORT_FILEUPLOAD=8686
- SERVICE_PORT_WEB=8080
ports:
- 8761:8762
network_mode: host
restart: always
I'm using Rest Template to invoke from Web service to Reservation service using the " http://sp-app-reservation:8182/rest/reservation ".我正在使用 Rest 模板使用“ http://sp-app-reservation:8182/rest/reservation ”从 Web 服务调用到预订服务。
I'm facing the below exception, and i can see my container running with the same name.我面临以下异常,我可以看到我的容器以相同的名称运行。
org.springframework.web.client.ResourceAccessException: I/O error on GET
request for "http://sp-app-reservation:8182/rest/reservation/":
sp-app-reservation; nested exception is java.net.UnknownHostException:
sp-app-reservation
You are using network_mode: host
, so you need to configure host record "sp-app-reservation" on the host OS level (for example "hardcode" it in /etc/hosts
).您正在使用network_mode: host
,因此您需要在主机操作系统级别配置主机记录“sp-app-reservation”(例如在/etc/hosts
对其进行“硬编码”)。
Better option will be to create docker network, where you can use docker container names and you will publish only selected ports to host OS.更好的选择是创建 docker 网络,您可以在其中使用 docker 容器名称,并且您将仅将选定的端口发布到主机操作系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.