Docker how to deploy dotnet nginx ? (without .csproj)

12/9/2019

Hello I want to deploy in docker: .net, kestrel and nginx. I have a project assembly without .csproj (it is possible or need .csproj ?) But when I try to deploy my .net project in Docker I had status Exitet.


Dockerfile

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

WORKDIR /app

COPY . .

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2

WORKDIR /app

COPY . .

EXPOSE 80

ENTRYPOINT ["bash"]

CMD ["build1", "WebApplication4.dll"]


My project files

appsettings.Development.json

appsettings.json

Dockerfile

WebApplication4

WebApplication4.deps.json

WebApplication4.dll

WebApplication4.pdb

WebApplication4.runtimeconfig.json

WebApplication4.Views.dll

WebApplication4.Views.pdb

web.config

wwwroot


docker ps --all

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

0f1880a89999 build1 "bash build1 WebAppl…" 4 seconds ago Exited (127) 3 seconds ago sleepy_bardeen


If you have a interes how to resolve. Answer.

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS final

WORKDIR /app

EXPOSE 80

COPY . .

ENTRYPOINT ["dotnet", "WebApplication4.dll"]

Right now. I try to find decision how to add nginx and kestrel ?

-- noute
.net
c#
docker
kubernetes
yaml

2 Answers

12/11/2019

Thanks. Right now try to add nginx and have problem with nginx Welcom default page.

nginx

Dockerfile

FROM nginx COPY nginx.conf /etc/nginx/ COPY default /etc/nginx/sites-enabled/

docker-compose.yaml

version: '3' services: dotnet: build: ./build2 expose: - "80"

nginx: build: ./nginx container_name: ngix-dotnet ports: - "80:80"

-- noute
Source: StackOverflow

12/11/2019

Microsoft suggests to use NGINX as a reverse proxy to .NET Core applications. You need to build the image and install NGINX in your dockerfile.

For example:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS final

# Nginx
RUN apt update && \
    apt install -y --no-install-recommends nginx && \
    rm -rf /var/lib/apt/lists/* && \
    apt clean && \
    rm /etc/nginx/nginx.conf
COPY MyProject/docker/nginx.conf /etc/nginx/nginx.conf

WORKDIR /app
ENV ASPNETCORE_URLS http://+:4000
EXPOSE 4000 80

As you can see I'm installing NGINX in my dockerfile and exposing 4000 and 80 port numbers. In the nginx.conf file NGINX listens for port 80 and pass requests to 4000 which is the port my .NET Core application listens.

You can find further information in this article: https://piotrgankiewicz.com/2017/06/12/asp-net-core-deployment-using-docker-nginx-and-ubuntu-server/

-- Hasan Akgün
Source: StackOverflow