简体   繁体   English

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

[英]how to access a localhost app from a container in docker-compose

I have a web app running outside of a container ( localhost:8090 ).我有一个在容器外运行的 web 应用程序( localhost:8090 )。
How can I access it from within a container in a docker-compose network?如何从docker-compose网络中的容器内访问它?

I tried to follow this answer that help for docker .我试图遵循这个docker有帮助的答案。

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:

Add network_mode: "host" to your graphql-engine: and remove port mapping: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 would listen on host port 8080 and would be able to connect to localhost:8090 graphql-engine将侦听主机端口 8080 并能够连接到localhost:8090

To make sure it worked, verify /etc/hosts file from the docker host is inside graphql-engine contianer.为确保它正常工作,请验证 docker 主机中的/etc/hosts文件是否位于graphql-engine中。

Docs 文档

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

相关问题 docker-compose:从docker容器访问localhost - docker-compose: access from docker container to localhost 使用 docker-compose 时无法从本地主机访问 docker 容器端口 - unable to access docker container port from localhost when using docker-compose 如何使用 docker-compose 而不是使用 docker bridge 从 docker 容器连接到 localhost:9092 - how to connect to localhost:9092 from docker container using docker-compose and not using docker bridge 如何使用docker-compose将localhost卷挂载到docker容器 - how to mount localhost volume to a docker container using docker-compose 如何从另一个 docker 容器中运行的应用程序启动 Docker-Compose 中的 docker 容器 - How do I start a docker container in Docker-Compose from an app running in another docker container 如何将docker-compose连接到容器网络和localhost网络 - How to connect docker-compose to container network and localhost network Docker-compose 从另一个容器访问 MySQL 容器 - Docker-compose MySQL container access from another container 如何使用 docker-compose 从 Docker 容器访问主机上的 sqlite 文件? - How to access sqlite file on host machine from a Docker container using docker-compose? 访问 Dockerfile 中的 container_name(来自 docker-compose) - Access container_name in Dockerfile (from docker-compose) 从主机访问 mariadb docker-compose 容器 - Access mariadb docker-compose container from host-machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM