Home:ALL Converter>How to dockerize my dotnet core + postgresql app?

How to dockerize my dotnet core + postgresql app?

Ask Time:2019-07-15T02:17:50         Author:xkcd

Json Formatter

I have a dotnet core application created with Angular template that communicates with a postgresql database.

On my local machine, I run the following command on my terminal to run the database container:

docker run -p 5432:5432 --name accman-postgresql -e POSTGRES_PASSWORD=mypass -d -v 'accman-postgresql-volume:/var/lib/postgresql/data' postgres:10.4

And then by pressing F5 in VsCode, I see that my application works great.

To dockerise my application, I added this file to the root of my application.

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env

# install nodejs for angular, webpack middleware
RUN apt-get update  
RUN apt-get -f install  
RUN apt-get install -y wget  
RUN wget -qO- https://deb.nodesource.com/setup_11.x | bash -  
RUN apt-get install -y build-essential nodejs

WORKDIR /app

# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "Web.dll"]

Now I think I have to create a docker-compose file. Would you please help me on creating my docker-compose.yml file?

Thanks,

Author:xkcd,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/57030000/how-to-dockerize-my-dotnet-core-postgresql-app
yy