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.
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.
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:
docker network create bride-network
postgreswith postgres database inside. make sure you add it to the 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
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: