【发布时间】:2021-07-02 16:39:26
【问题描述】:
我有一个 Spring Boot 配置服务器在 localhost 的 8888 端口上运行。我想从 docker 容器内访问此服务。我不能将此服务放在同一个 docker-compose 和同一个网络中。
服务:http://localhost:8888/cpo-executor/dev
使用我的 ip:http://192.168.0.6:8888/cpo-executor/dev
我已经在浏览器上检查了这个地址,它正在工作。当我尝试从 docker 容器内部访问时出现错误:
docker exec -it 7febe846f2ea /bin/bash
curl http://192.168.0.6:8888/cpo-executor/dev
错误:
curl: (7) Failed to connect to 192.168.0.6 port 8888: Connection timed out
我试图启动我的容器,将“network_mode: host”放入 docker-compose,但我最终陷入了另一个错误,因为一个容器没有与另一个容器通信。
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Caused by: java.net.UnknownHostException: mysql
如何从 docker 容器内的主机访问服务?
【问题讨论】:
-
我假设
mysql是您的 docker-compose 文件中定义的另一个服务?
标签: docker docker-compose host spring-cloud-config