.net core 打包docker 镜像

一、新建项目:Linux.Web

二、添加docker file

三、将Dockerfile 移动到外层目录

 由于项目使用了私仓,所以添加一行:

COPY ["nuget.config", "/src"]

完事的Dockerfile 内容: 

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["Linux.Web/Linux.Web.csproj", "Linux.Web/"]
COPY ["nuget.config", "/src"]
RUN dotnet restore "Linux.Web/Linux.Web.csproj"
COPY . .
WORKDIR "/src/Linux.Web"
RUN dotnet build "Linux.Web.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Linux.Web.csproj" -c Release -o /app/publish

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

 四、添加nuget.config

私仓:  <add key="saas" value="http://192.168.1.108:71/nuget" />

 

完整的nuget.config内容: 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- defaultPushSource key works like the 'defaultPushSource' key of NuGet.Config files. -->
    <!-- This can be used by administrators to prevent accidental publishing of packages to nuget.org. -->
    <config>
        <add key="defaultPushSource" value="https://contoso.com/packages/" />
    </config>

    <!-- Default Package Sources; works like the 'packageSources' section of NuGet.Config files. -->
    <!-- This collection cannot be deleted or modified but can be disabled/enabled by users. -->
    <packageSources>
        <add key="saas" value="http://192.168.1.108:71/nuget" />
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    </packageSources>

    <!-- Default Package Sources that are disabled by default. -->
    <!-- Works like the 'disabledPackageSources' section of NuGet.Config files. -->
    <!-- Sources cannot be modified or deleted either but can be enabled/disabled by users. -->
   
</configuration>

五、拷贝到linux 服务器:/data/wwwroot

六、打包镜像

docker build -t linux.web:v1.0.1 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值