如何通过docker-compose使docker容器与localstack docker容器通信? [英] How to make a docker container communicate with the localstack docker container with docker-compose?

查看:129
本文介绍了如何通过docker-compose使docker容器与localstack docker容器通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在docker容器中设置一个应用程序.我希望该应用程序能够连接到本地堆栈堆栈容器本地堆栈文档.当我运行 docker-compose up 时,容器成功启动.我可以运行docker-compose文件中未包含的单独的Java应用程序,该应用程序将成功连接到localstack容器.但是与localstack一起启动的应用程序无法连接.我已经看了看docker docs和localstack docs,但我想不出如何使这些东西相互通信的方法.任何帮助将不胜感激.这是我的 docker-compose 文件:

I am setting up an application inside a docker container. I want this application to be able to connect with the localstack stack container localstack docs. When i run docker-compose up the containers start up successfully. I can run a seperate java application not included with in docker-compose file that will connect successfully to the localstack container. But the application that starts up along with the localstack cannot connect. Ive looked at the docker docs and localstack docs and I cant figure out how to get these things to communicate with one another. Any help would be greatly apprecaited. Here is my docker-compose file:

version: '3.4'

networks:
  default:
    driver: bridge

services:
  jc:
    build:
      context: .
      dockerfile: ./Dockerfile
      args:
      - PORT=5001
      network: host
    image: jc
    depends_on:
    - localstack
    container_name: jc
    ports:
    - 5001:5001
    links:
    - localstack
    environment:
    - SPRING_PROFILES_ACTIVE=local
  localstack:
    image: localstack/localstack
    ports:
    - "4567-4584:4567-4584"

我收到的错误消息是:

sqs.SqsPoller app = jc version = 2.0.1.0:轮询消息时发生异常:无法执行HTTP请求:连接到localhost:4576 [localhost/127.0.0.1]失败:连接被拒绝(连接被拒绝)

sqs.SqsPoller app=jc version=2.0.1.0 : An exception occurred while polling for messages: Unable to execute HTTP request: Connect to localhost:4576 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

推荐答案

关于此错误

连接到localhost:4576 [ localhost/127.0.0.1 ]失败:连接被拒绝(连接被拒绝)

Connect to localhost:4576 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

似乎您已经在服务 jc 中准备好设置了,对于您的问题应用程序也需要同样的设置.

Seems you have the setting ready in service jc, you need the same for your problem application.

links:
- localstack

我猜您的应用程序也在另一个docker中运行,而不是直接在主机上运行.因此,您无法从应用程序容器访问 localhost:4567 ,因为在容器本身无法访问这些aws模拟的服务.两种解决方案:

I guess your application is running in another docker as well, not on host directly. So you can't access localhost:4567 from application container, because these aws emulated services are not reachable in container itself. Two solutions:

  1. 将localstack容器链接到您的应用程序.例如,如果链接名称为 localstack ,则可以使用 localstack:4567

获取主机的真实IP地址,并使用 IP:4567

get the real IP address of host, access with IP:4567

这篇关于如何通过docker-compose使docker容器与localstack docker容器通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆