简体   繁体   English

无法在 docker 容器之间进行通信 - 连接被拒绝

[英]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?我该怎么做才能使其与容器名称一起使用?

Try using backend.url=http://backend:8080 .尝试使用backend.url=http://backend:8080 Port 8888 is used for accessing backend from your host machine, while 8080 is actual container's port.端口 8888 用于从主机访问后端,而 8080 是实际容器的端口。 Check more information here .在此处查看更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker容器中数据库容器和docker中的java容器之间的连接被拒绝 - Connection refused in Docker container between database container and java container in docker 多容器 Docker 应用程序 - 容器之间的连接被拒绝 - Multi Container Docker app - Connection Refused between containers 尝试在Docker容器之间进行连接时连接被拒绝(连接被拒绝) - Connection refused (Connection refused) while trying to connect between docker containers 连接拒绝从 docker 连接到 Elasticsearch docker 容器 - Connection Refused connecting from docker to Elasticsearch docker container 连接被拒绝:访问在Docker容器中运行的Spring Boot应用程序 - Connection refused: accessing a spring boot application running in docker container Rabbitmq连接被拒绝,在Linux服务器上的docker容器中运行 - Rabbitmq connection refused , runs inside docker container on a linux server 连接到 jmeter 从站 docker 容器时出现连接被拒绝错误 - Connection refused error while connecting to jmeter slave docker container 从 docker 容器连接到主机 mysql db 时连接被拒绝 - Connection refused when connecting to host mysql db from docker container java.net.connectexception 连接被拒绝(连接被拒绝):无法从 docker 容器连接到本地 rabbitmq - java.net.connectexception connection refused (connection refused) : not able to connect to local rabbitmq from docker container docker容器内的spring boot引发java.net.ConnectException:连接被拒绝(连接被拒绝) - Spring boot inside docker container throws java.net.ConnectException: Connection refused (Connection refused)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM