# 基础镜像,基于什么语言/平台开发
FROM mcr.microsoft.com/dotnet/core/sdk:2.2
# 镜像信息
LABEL author="monk" email="monksoul@outlook.com" version="1.0"
# 创建一个工作目录(或者说是当前目录)
WORKDIR /app
# 拷贝所有文件到当前上下文目录
ADD . .
# 运行一条指令
RUN dotnet build "app.csproj" -c Release -o /app/push
# 切换到当前目录
WORKDIR /app/push
# 设置环境变量
ENV NAME=monk AUTHOR=monk
# 导出端口
EXPOSE 80
# 导出数据卷
VOLUME ["/uploads"]
# 构建完成后最后执行的命令
ENTRYPOINT [ "dotnet","app.dll" ]
FROM nginx
ADD . /usr/share/nginx/html
EXPOSE 80
docker build -t nginx-test:v1.0.0 .
docker run --name nginx-testv1 -p 5002:80 -d nginx-test:v1.0.0
一个简单的ASP.NET Core 项目 Dockerfile
dotnet new razor
dotnet publish "asp.net core.csproj" -c Release -o ./publish
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
ADD ./publish /app
EXPOSE 80 443
ENTRYPOINT ["dotnet","asp.net core.dll"]
docker build -t aspnetcore:v1.0.0 .
docker run --name aspnetcorev1 -p 5003:80 -d aspnetcore:v1.0.0
docker build -t nginx-test:v2.0.0 .
docker build -t aspnetcore:v2.0.0 .