今天试用了下mac 版本的dotnetcore sdk,发现还是很方便的,同时官方的容器运行方式,我相对小了好多
同时使用多阶段构建的方式运行dotnetcore
下载地址:
https://dotnet.microsoft.com/download
选择版本下载并安装即可
使用dotnetcore 命令创建的
mkdir app
cd dotnet new mvc
dotnet publish -c Release -o out
version: "3"
services:
app:
build:
context: ./
dockerfile: Dockerfile
image: dalongrong/dotnetcoreaspnet-demo:alpine
ports:
- "80:80"
app-build:
build:
context: ./
dockerfile: Dockerfile-multistage
image: dalongrong/dotnetcoreaspnet-demo2:alpine
ports:
- "8080:80"
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine
LABEL AUTHOR="dalongrong"
LABEL EMAIL="1141591465@qq.com"
WORKDIR /app
COPY /app/out /app/
EXPOSE 80
ENTRYPOINT [ "dotnet","/app/app.dll" ]
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /app
COPY app/*.csproj ./
RUN dotnet restore -s https://api.nuget.org/v3/index.json
COPY app/. /app/
RUN dotnet restore app.csproj
RUN dotnet publish -c Release -o out
?
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine
LABEL AUTHOR="dalongrong"
LABEL EMAIL="1141591465@qq.com"
WORKDIR /app
COPY --from=build /app/out .
EXPOSE 80
ENTRYPOINT [ "dotnet","app.dll" ]
对于aspnet 运行时环境我使用的alpine 这样稍小点
docker-compose up -d
https://github.com/rongfengliang/dotnetcore-aspnet-docker
https://github.com/dotnet/dotnet-docker/tree/master/samples/aspnetapp
https://docs.docker.com/engine/examples/dotnetcore/
原文:https://www.cnblogs.com/rongfengliang/p/11329625.html