ASP.NET Core分布式项目实战

默认教学计划
1067人加入学习
(33人评价)
价格 ¥398.00
教学计划

新建一个控制台项目:console

dotnet new console

制作dockerfile文件

FROM microsoft/dotnet

WORKDIR /app

COPY . /app

CMD ["dotnet","run"]

打包镜像

docker build -t liuguojiang/console:dev

docker images

docker run --name console=dev liuguojiang:dev

docker ps -a

docker logs console-dev

 

制作新dockerfile文件

FROM microsoft/dotnet:sdk AS build-env

WORKDIR /code

COPY *.csproj /code

RUN dotnet restore

COPY . /code

RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:runtime

WORKDIR /app

COPY --from=build-env /code/out /app

ENTRYPOINT ["dotnet","console.dll"]

 

docker build -t liuguojiang/console:build

dotnet run --name console-prod liuguojiang/console:prod

 

 

 

 

[展开全文]

docker pull microsoft/dotnet的时候,使用阿里云镜像,可能导致2.1-sdk无法获取,需要使用docker原始路径。

dotnet core 2.1:

[dockerfile]内容:

FROM microsoft/dotnet:2.1-runtime AS base
WORKDIR /app

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY console.csproj /src
RUN dotnet restore console.csproj
COPY . .
WORKDIR /src
RUN dotnet build console.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish console.csproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "console.dll"]

[展开全文]

-deps 自包含 :不用关心服务器的版本

推荐-runtime比较小

[展开全文]

Docker build 命令

docker build [options] <path|URL>

Dockerfile

{

FROM|

COPY/ADD|

RUN/CMD|

ENTRYPOINT|

ENV|

EXPOSE|

WORKDIR

}

microsoft/dotnet

microsoft/dotnet:sdk

microsoft/dotnet:<version>-runtime

 

Dockerfile

From scratch  用到空白镜像

FROM microsoft/dotnet

WORKDIR /app

COPY . /app

CMD ["dotnet","run"]

 docker build -t anker/console:dev .

FROM microsoft/dotnet:sdk AS build_env

WORKDIR /code

COPY *.csproj /code

RUN dotnet restore

COPY . /code

RUN dotnet publish -c Release -o out

FROM microsoft/dotnet:runtime

WORKDIR /app

COPY --from=build_env /code/out /app

ENTRYPOINT ["dotnet","console.dll"]

docker build -t anker/console:prod .

 

 

 

 

 

 

 

 

[展开全文]

授课教师

程序员

课程特色

下载资料(2)
视频(144)
讨论(1)
图文(2)