0
votes

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 ?

2
you suppose to build it in docker container not just to copy...Oleg Butuzov
Can you please share the container logs? (docs.docker.com/engine/reference/commandline/logs) Also, the entry point is "BASH", are you trying to use this container as builder? If so, your build process is not correct (docs.docker.com/develop/develop-images/multistage-build).Armando Cuevas
Sorry I didn't write. But I am recently started to study docker and how to deploy and I don't know how will be right. But i want just to deploy .net assembly in docker. No I don't want to build process because it is ready assembly.noute
Sorry but when I try to run container without ENTRYPOINT ["bash"] I had error Error response from daemon: OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"build1\": executable file not found in $PATH": unknown docker logsnoute
Hello thx for your help. I resolve my problem. Right now. I try to find decision how to add nginx and kestrel ?noute

2 Answers

2
votes

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/

0
votes

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"