0

I have a RESTful application that takes a callback URL as an argument running on port 8000. It does some work and calls the callback URL to make sure that it should continue work and calls if anything goes wrong. In my tests, I just spin up an HTTP server on localhost port 8009 to wait for responses.

When I run the application directly, it works fine because the localhost is the same. However, when I run the application locally in a container, it obviously doesn't work because of the network isolation of the container. Here's part of my docker-compose.yml:

version: '3'
services:
  app:
    build: .
    ports:
      - "8000:8000"

I tried to add - "8009:8009" under ports, but that only goes one direction. I can call port 8000 to call the API, but I can't figure out how to allow the container to call my laptop's http://localhost:8009.

Any idea how to allow the container to call out to another port on my laptop, or if there's a better way to test the callback functionality? I could run the tests inside the container, but I like being able to run them separately.

Al-waleed Shihadeh
  • 2,697
  • 2
  • 8
  • 22
EmptyArsenal
  • 7,314
  • 4
  • 33
  • 56

1 Answers1

-1

Use --network: "host" in your docker-compose file, then localhost in your docker container will point to your docker host.

If your laptop is running Mac and Windows, use host host.docker.internal, that resolves to host machine's IP address and then connect using your laptop hostname.

Munish
  • 1,377
  • 9
  • 16