1

I have a web app running outside of a container (localhost:8090).
How can I access it from within a container in a docker-compose network?

I tried to follow this answer that help for 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:
itaied
  • 6,827
  • 13
  • 51
  • 86

1 Answers1

2

Add network_mode: "host" to your graphql-engine: and remove port mapping:

  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

To make sure it worked, verify /etc/hosts file from the docker host is inside graphql-engine contianer .

Docs

rok
  • 9,403
  • 17
  • 70
  • 126