Deployment learning of Nginx + Docker multi-stage construction

A website was deployed a few days ago. It turns out that I have been uploading files through ftp after publishing. Several tycoons told me about multi-stage construction. At this time, I don't need to publish any more. I will directly add docker support to the project.

#See to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM AS base

FROM AS build
COPY ["amusinghoS.App/amusinghoS.App.csproj", "amusinghoS.App/"]
COPY ["amusinghoS.Entity/amusinghoS.EntityData.csproj", "amusinghoS.Entity/"]
COPY ["amusinghoS.Shared/amusinghoS.Shared.csproj", "amusinghoS.Shared/"]
COPY ["amusinghoS.Services/amusinghoS.Services.csproj", "amusinghoS.Services/"]
COPY ["amusinghoS.Redis/amusinghoS.Redis.csproj", "amusinghoS.Redis/"]
RUN dotnet restore "amusinghoS.App/amusinghoS.App.csproj"
COPY . .
WORKDIR "/src/amusinghoS.App"
RUN dotnet build "amusinghoS.App.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "amusinghoS.App.csproj" -c Release -o /app/publish

FROM base AS final
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "amusinghoS.App.dll"]

The most important ones are those copies. As long as they are dependent on your project, they are all packaged and built into a mirror image.

Then there is Nginx. The configuration file is as follows. The port aiming at 1314 must be the external network port of docker!

worker_processes  1;
events {
    worker_connections  1024;
http {
    include mime.types;
    default_type  application/octet-stream;
    sendfile on;
    keepalive_timeout  65;
    server {
        listen 80;
        server_name localhost;
        error_page 500 502 503 504 /50x.html;
        location / {
                proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;

At this time, visit to visit docker's 1314 internal 5001 website.

Tags: Linux Docker Redis ftp SDK

Posted on Mon, 25 May 2020 11:01:36 -0400 by kotun