Add to .Net Core Docker file support and run

1, add a Dockerfile file, move it to the solution folder, the template is as follows:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.sln .
COPY aspnetapp/*.csproj ./aspnetapp/
RUN dotnet restore
 
# copy everything else and build app
COPY aspnetapp/. ./aspnetapp/
WORKDIR /app/aspnetapp
RUN dotnet publish -c Release -o out
 
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
WORKDIR /app
COPY --from=build /app/aspnetapp/out ./
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS Build
WORKDIR /app
  
# copy csproj and restore as distinct layers
COPY *.sln .
COPY NetCore-Learn-LocalMsSql/*.csproj ./NetCore-Learn-LocalMsSql/
RUN dotnet restore
 
# copy everything else and build app
COPY NetCore-Learn-LocalMsSql/. ./NetCore-Learn-LocalMsSql/
WORKDIR /app/NetCore-Learn-LocalMsSql
RUN dotnet publish -c Release -o out
 
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
WORKDIR /app
COPY --from=build /app/NetCore-Learn-LocalMsSql/out ./
ENTRYPOINT ["dotnet", "NetCore-Learn-LocalMsSql.dll"]

2. Switch to the solution folder, PS operation began Build, need to pay attention to lowercase.

docker build -t netcore-learn-localmsql .

3, Docker Images view mirror to create circumstances

4, designated port, start running.

docker run -it -p 3000:80 --name netcorelearnlocalmssql netcorelearnlocalmssql:latest

Guess you like

Origin www.cnblogs.com/craigtaylor/p/10971250.html