Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

381
Views
Install PostgreSQL into a asp.net core container

I'm a beginner to Docker world. I've created an ASP.net Core Web API and ran successfully on localhost with PostgreSQL. Now, I've added the WebAPI into a Docker container. I'm using Windows 10, Visual Studio 2015, Docker for Windows 10 and Powershell. Now the problem is, I can't figure it out the following.

  1. How to setup PostgreSQL inside my container?
  2. How to create a DB and Tables?
  3. How to connect the above DB with the WebAPI?

It's giving a "Connection refused" error when I try to call the API. The DB connection fails. I believe it's because there's no DB inside the container. I couldn't find a proper way for a beginner to understand this procedure. Any help with steps would be really helpful.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You want to run each application in a seperate container otherwise you end up with the same application hell as before.

But you have to connect the containers together using a network.

steps to do so:

  1. create a bridge network with a name: bride-network: docker network create bride-network
  2. run container named postgres with postgres database inside. make sure you add it to the network: --network bridge-network
  3. add your application ad docker container: also add it to this network with --network bridge-network

Now your application can reach the postgres database with the hostname http://postgres (basically http://[container-name]).

To do this in 1 go you can create a docker-compose.yml file and run docker-compose -f yourfile.yml up to create everything at once

Why split containers

The idea of docker is that 1 container runs 1 application. When this process stops docker knows that the container has stopped/died. If you add multiple apps in 1 container docker will not know. Also it could be that apps create problems, eg: what if both apps register to listen to the same ports?

Another problem case is when you want to scale up: create duplicate containers. do you then als want to scale up the database 1=1 with your app? where is your single source of truth then?

So you split up 1 app per container:

  • Every app runs in its own sandbox, and cannot be hurt/communicate by any other app/container only over http/udp.
  • You can scale them up (horizontally) individually.
  • You can configure them individually through environment variables.
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!