gpt4 book ai didi

docker - 如何从docker-compose中的容器访问localhost应用

转载 作者:行者123 更新时间:2023-12-02 19:02:08 31 4
gpt4 key购买 nike

我有一个在容器(localhost:8090)之外运行的Web应用程序。
如何从docker-compose网络中的容器中访问它?

我试图遵循thisdocker有帮助的答案。

version: '3.6'
services:
postgres:
image: postgres
restart: always
volumes:
- db_data:/var/lib/postgresql/data
networks:
- host
graphql-engine:
image: hasura/graphql-engine:v1.0.0-beta.6
ports:
- "8080:8080"
depends_on:
- "postgres"
restart: always
environment:
HASURA_GRAPHQL_AUTH_HOOK: "http://localhost:8090/verify"
volumes:
db_data:

最佳答案

network_mode: "host"添加到您的graphql-engine:中并删除端口映射:

  graphql-engine:
image: hasura/graphql-engine:v1.0.0-beta.6
depends_on:
- "postgres"
restart: always
network_mode: "host"
environment:
HASURA_GRAPHQL_AUTH_HOOK: "http://localhost:8090/verify"
graphql-engine将在主机端口8080上侦听,并能够连接到 localhost:8090
为确保其正常工作,请确认docker主机上的 /etc/hosts文件位于 graphql-engine contianer内部。

Docs

关于docker - 如何从docker-compose中的容器访问localhost应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58472920/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com