Setup docker-compose to make OAuth flow work

  docker, docker-compose, oauth, oauth-2.0

I am trying to setup docker compose for local development, which consist from two services. OAuthServer and ClientApp.

The issue is that communication on host machine must work.
Both services are accessible on localhost:3000 (ClientApp) and localhost:4000 (OAuthServer). That is simple.

But also ClientApp must be able to communicate with OAuthServer directly. And that’s where the problem is. Standard OAuth flow does expect that the ClientApp will be always communicating with OAuthServer on same url.

The URL for ClientApp reach OAuthServer is oauthserver:4000.

One possible solution is to use network_mode: host, but unfortunately I am on Mac OS and it doesn’t seems to work.

Can you please suggest any solution?

version: '3'
services:
  clientapp:
    build: .
    depends_on:
      - oauthserver
    environment:
      - AUTH_SERVER_URL=http://localhost:4000
    ports:
      - 3000:3000
  oauthserver:
    image: myauthserver
    depends_on:
      - db
    ports:
      - 4000:4000
  db:
    image: postgres:latest
    ports:
      - 5432

Source: StackOverflow

LEAVE A COMMENT