[英]cannot communicate between docker container - connection refused
I have a stack of n services defined in a docker compose file:我在 docker compose 文件中定义了一堆 n 个服务:
version: "3.7"
services:
db:
...
backend:
image: $IMAGE_DEV_BACKEND
container_name: "backend"
hostname: backend
ports:
- "8888:8080"
depends_on:
- db
networks:
- backend
frontend:
image: $IMAGE_DEV_FRONTEND
container_name: "frontend"
hostname: frontend
depends_on:
- backend
networks:
- backend
- traefik_default
volumes:
data:
networks:
backend:
driver: bridge
external:
name: backend
traefik_default:
driver: bridge
external:
name: traefik_default
All container are in the same network.所有容器都在同一个网络中。
In the frontend spring app I have a following spring configuration:在前端 spring 应用程序中,我有以下 spring 配置:
backend.url=http://backend:8888
when the frontend application tries to connect to the backend one I get backend.url=http://backend:8888
当前端应用程序尝试连接到后端时我得到
ERROR DefaultFormCommandBean:529 - Error while performing action "datastoreAction": I/O error on POST request for "http://backend:8888/oauth/token": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://backend:8888/oauth/token": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:674)
when I use the IP address of the host with the docker daemon, everything works flawlessly, the containers can talk to each other.当我将主机的 IP 地址与 docker 守护程序一起使用时,一切正常,容器可以相互通信。
What can I do to make it work with the container names?我该怎么做才能使其与容器名称一起使用?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.