首页 > Web开发 > 详细

dotnetcore docker 简单运行

时间:2019-08-09 23:47:28      阅读:152      评论:0      收藏:0      [点我收藏+]

今天试用了下mac 版本的dotnetcore sdk,发现还是很方便的,同时官方的容器运行方式,我相对小了好多
同时使用多阶段构建的方式运行dotnetcore

安装sdk

下载地址:
https://dotnet.microsoft.com/download
选择版本下载并安装即可

简单demo

使用dotnetcore 命令创建的

  • 创建简单demo
mkdir app
cd dotnet new mvc 
  • 生成发布文件
dotnet publish -c Release -o out

集成docker

  • docker-compose 文件
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"
  • Dockerfile
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/

dotnetcore docker 简单运行

原文:https://www.cnblogs.com/rongfengliang/p/11329625.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!