itaied
itaied

Reputation: 7107

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

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:

Upvotes: 1

Views: 279

Answers (1)

rokpoto.com
rokpoto.com

Reputation: 10718

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

Upvotes: 2

Related Questions