0

I have a backend API and an identity manager service, each of them have a compose file. On every API request the code should communicate with the identity service (validate the JWT token), but it is on a different network. How should I configure the networks to reach each other?

version: "3.9"
services:
    api:
        build: .
        ports:
            - 5000:80
            - 5001:443
        depends_on:
            - db
        environment:
            - ASPNETCORE_ENVIRONMENT=Production
            - ConnectionString=Server=db,1433;Database=test;User Id=sa;Password=${SQL_PASSWORD}
            - JWTSettings__Issuer=${AUTH_ISSUER}
            - JWTSettings__Authority=${AUTH_AUTHORITY}
            - JWTSettings__Audience=${AUTH_AUDIENCE}
    
    db:
        image: mcr.microsoft.com/mssql/server
        user: root
        ports:
            - 1433:1433
        environment:
            - SA_PASSWORD=${SQL_PASSWORD}
            - ACCEPT_EULA="Y"
version: "3.9"
services:
    auth:
        image: quay.io/keycloak/keycloak
        environment:
            KEYCLOAK_USER: admin
            KEYCLOAK_PASSWORD: admin
        ports:
            - 4000:8080
KDani
  • 358
  • 4
  • 19
  • Have you checked this: [Communication between multiple docker-compose projects](https://stackoverflow.com/questions/38088279/communication-between-multiple-docker-compose-projects)? – tgogos Oct 12 '21 at 09:29

1 Answers1

2

The default network is $prefix_default, where the $prefix is by default the name of the folder containing the docker-compose.yml file. This can set by using the -p parameter with docker-compose, see docs.

You can use the network from the other docker-compose stack, by defining it in the second docker-compose.yml like this:

networks:
    project1_default: 
      external: true

Alternatively, you can create a docker network manually[2], and refer to it in both of your docker-compose.yml files.

retfma
  • 71
  • 2