Install PostgreSQL into a asp.net core container Install PostgreSQL into a asp.net core container docker docker

Install PostgreSQL into a asp.net core container


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.