1

I am trying to configure docker-compose file to have possibility to run several services of the whole application (api - .net web api, db - PostgreSQL, rabbitmq, pgadmin). However, an additional challenge is that the api connects in parallel to two databases - one is for internal use - PostgreSQL. On the other hand, there is a second database (Microsoft SQL), which is located on the host computer and cannot be moved to any other location (moving to docker compose is unfortunately not an option). How can I configure the docker file to be able to connect to both the services inside docker compose and the database put on the host machine.

The docker compose file looks like this


services:
  api:
    image: api:latest
    ports:
      - "5000:80"
    depends_on:
      - db
      - rabbitmq
    environment:
      - ASPNETCORE_ENVIRONMENT=Production

  db:
    image: postgres:latest
    environment:
      - POSTGRES_DB=data-exchange
      - POSTGRES_USER=root
      - POSTGRES_PASSWORD=password
    ports:
      - "5432:5432"
    volumes:
      - ./pgdata:/var/lib/postgresql/data

  rabbitmq:
    image: rabbitmq:3.12-management
    ports:
      - "5672:5672"
      - "15672:15672"
    environment:
      - RABBITMQ_DEFAULT_USER=guest
      - RABBITMQ_DEFAULT_PASS=guest

  pgadmin:
    image: dpage/pgadmin4:7.7
    ports:
      - "8081:80"
    environment:
      - [email protected]
      - PGADMIN_DEFAULT_PASSWORD=password
    depends_on:
      - db
    volumes:
      - ./pgadmin:/var/lib/pgadmin

volumes:
  pgdata:
  pgadmin:

And this is what the file that is used for the connection looks like - appsettings.json

"Context": "Server=host.docker.internal\\SQLEXPRESS,1433;Database=db_name;User ID=user;pwd=password;"

I've read a whole bunch of articles, however I haven't found anything useful that could help in this case? Maybe I should configure networks accordingly?

Let me just add that such trivial problems I rather eliminated (such as allowing remote connections to the database).

I attach a graphic to make it clear what the problem is.

enter image description here

Greetings and have a great day!

1
  • Well this seems confusing: Server=host.docker.internal\\SQLEXPRESS,1433; You're trying to mix instance name resolution (the \\SQLEXPRESS portion) and port number specification (the ,1433 portion) in the same connection string. Choose one method appropriate to the Edition and configuration of the SQL Server you have installed on the Docker host. (Express edition isn't likely to be listening on port 1433.) Also... host.docker.internal is only intended for use on Docker Desktop, you'll need to find a different solution when you push your solution up to the cloud. Commented Oct 6, 2023 at 23:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.