dotnetcore docker 简单运行

今天试用了下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 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/

posted on 2019-08-09 21:14  荣锋亮  阅读(575)  评论(0编辑  收藏  举报

导航