您的第一行 FROM 完全未使用。而是将您的FROM base
线路更改为FROM mcr.microsoft.com/dotnet/core/runtime:2.2-stretch-slim
这个问题可能是由于 Kaniko **/someDir .dockerignore 模式没有被正确观察。我注意到 /obj、/bin、.idea (rider) 和 .git 文件夹都被复制了。
https://github.com/GoogleContainerTools/kaniko/issues/1396
您也没有使用基于 alpine 的 sdk 和运行时映像。
在中dotnet restore command
您可以使用该--no-cache
标志,因为 docker 层缓存会处理该问题。
dotnet publish
进行构建,因此您可以跳过调用dotnet build
. 如果您想执行测试,您可以dotnet test
致电
dotnet restore
您在所有后续命令中都明确调用,因此dotnet
您可以使用该--no-restore
选项。
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-alpine AS base
#Add whatever tools you need to the base image
RUN apk add --update --no-cache git bash curl zip; \
export PATH="$PATH:/root/.dotnet/tools"; \
dotnet tool install --global dotnet-xunit-to-junit --version 1.0.2
FROM base AS restore
WORKDIR /src
COPY ["TaikunBillerPoller.csproj", ""]
RUN dotnet restore --no-cache "TaikunBillerPoller.csproj"
COPY . .
FROM restore as publish
ARG VERSION="0.0.0"
RUN dotnet test "TaikunBillerPoller.csproj" --configuration Release --no-restore
RUN dotnet publish "TaikunBillerPoller.csproj" --output /app --configuration Release --no-restore /p:Version=$VERSION
FROM mcr.microsoft.com/dotnet/core/runtime:2.2-alpine AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "TaikunBillerPoller.dll"]
在 2015 年的 Mac 上,我有一个 asp.net 微服务,它使用正常的时间构建、测试、发布和创建 beanstalk_bundle zip docker build
:
- 51s 无缓存
- 22s 代码更改
- <1s 无代码更改(管道 yml 更改)
Kaniko 增加了开销,因为层缓存是远程完成的一些存储库(通常)。这一次将很大程度上取决于您如何配置 Kaniko 缓存和挂载卷。这是我在本地机器上用于调试的东西。
#!/bin/bash
# Assuming this is either not an ephemeral machine, or the ephemeral machine
# maps the cache directory to permanent volume.
# We cache images into the local machine
# so that the Kaniko container, which is ephemeral, does not have to pull them each time.
docker run -v $(pwd):/workspace gcr.io/kaniko-project/warmer:latest \
--cache-dir=/workspace/cache \
--image=mcr.microsoft.com/dotnet/core/sdk:2.2-alpine \
--image=mcr.microsoft.com/dotnet/core/aspnet:2.2-alpine
docker run -it --rm \
-v `pwd`:/workspace \
-v `pwd`/kaniko-config.json:/kaniko/.docker/config.json:ro \
-v `pwd`/reports:/reports \
-v `pwd`/beanstalk_bundle:/beanstalk_bundle \
gcr.io/kaniko-project/executor:latest \
--dockerfile "buildTestPublish.Dockerfile" \
--destination "registry.gitlab.com/somePath/theImageName:theVersion" \
--skip-unused-stages \
--cache \
--cache-dir=/workspace/cache \
--verbosity=trace