我在一个在Jenkins中构建和部署的Docker容器中运行了一个小型.NET Core Web应用程序。 docker存储库通过Quay托管。
最初,构建&部署容器。但随着时间的推移,每个构建和部署已经花费了越来越长的时间,到现在的时间长达一个多小时。以下是日志开头的一些有希望的相关部分:
从git中检出存储库:
...
+ ./build.sh
+ REPO=quay.io/my/dir
+ IMAGE=quay.io/my/dir:dddaca1fd347b1fabea342a6a65431b68f793ad4
+ docker pull quay.io/my/dir
Using default tag: latest
latest: Pulling from my/dir
Digest: sha256:9a654ad205764a668c1fc531c0972d1273b0920dc8282a8c7b6498482cee7975
Status: Image is up to date for quay.io/my/dir:latest
+ docker build -t quay.io/my/dir:dddaca1fd347b1fabea342a6a65431b68f793ad4 .
Sending build context to Docker daemon 121.9 kB
Sending build context to Docker daemon 121.9 kB
...
按下泊坞窗图片,我认为:
...
+ '[' true = true ']'
+ docker tag -f quay.io/my/dir:dddaca1fd347b1fabea342a6a65431b68f793ad4 quay.io/my/dir:latest
+ '[' true = true ']'
+ docker tag -f quay.io/my/dir:dddaca1fd347b1fabea342a6a65431b68f793ad4 quay.io/my/dir:latest-master
+ docker tag -f quay.io/my/dir:dddaca1fd347b1fabea342a6a65431b68f793ad4 quay.io/my/dir:master-62
+ docker push quay.io/my/dir
The push refers to a repository [quay.io/my/dir] (len: 26)
...
然后,时间主要由以下几个小组占用:
...
7db029aae55d: Preparing
7db029aae55d: Pushing
7db029aae55d: Pushed
55d4937daea6: Preparing
55d4937daea6: Pushing
55d4937daea6: Pushed
7ed278cf0e04: Preparing
7ed278cf0e04: Pushing
7ed278cf0e04: Pushed
master-49: digest: sha256:8ce1e...<more of the key>...90503 size: 21007
4c16f41d1cc1: Image already exists
8f1aae847e7a: Image already exists
28a352fdaf13: Image already exists
80151bfc7fc5: Image already exists
54c7eb98ce04: Preparing
54c7eb98ce04: Pushing
54c7eb98ce04: Pushed
b1131d0b29bb: Preparing
... more of the same
我是Docker的新手,非常感谢他们的帮助。这是我的build.sh
和Dockerfile
:
build.sh
#!/bin/bash -ex
REPO=quay.io/my/dir
IMAGE=$REPO:$GIT_COMMIT
docker pull $REPO
docker build -t $IMAGE .
docker run --rm $IMAGE /bin/bash -c "cd /app/test/Project.Tests && dotnet test"
if [ "$TAG_LATEST" = true ]; then
docker tag -f $IMAGE $REPO:latest
fi
if [ "$TAG_LATEST_MASTER" = true ]; then
docker tag -f $IMAGE $REPO:latest-master
fi
# $TAG defined prior to running script
docker tag -f $IMAGE $REPO:$TAG
docker push $REPO
Dockerfile
FROM microsoft/dotnet:1.1.1-sdk
EXPOSE 5000
COPY . /app
WORKDIR /app
RUN cd src/Project && dotnet restore --configfile NuGet.config --no-cache
RUN cd test/Project.Tests && dotnet restore --no-cache
RUN dotnet build
WORKDIR /app/src/Project
CMD ["dotnet", "run", "--server.urls", "https://0.0.0.0:5000"]
图片历史记录
$ sudo docker history quay.io/my/dir
IMAGE CREATED CREATED BY SIZE COMMENT
0e58e5457605 4 days ago /bin/sh -c #(nop) CMD ["dotnet" "run" "--s... 0B
<missing> 4 days ago /bin/sh -c #(nop) WORKDIR /app/src/Project 0B
<missing> 4 days ago /bin/sh -c dotnet build 782kB
<missing> 4 days ago /bin/sh -c cd test/Project.Tests && dotn... 15.8MB
<missing> 4 days ago /bin/sh -c cd src/Project && dotnet rest... 2.4MB
<missing> 4 days ago /bin/sh -c #(nop) WORKDIR /app 0B
<missing> 4 days ago /bin/sh -c #(nop) COPY dir:c9cbed0051facc2... 62kB
<missing> 3 weeks ago /bin/sh -c #(nop) EXPOSE 5000/tcp 0B
<missing> 4 weeks ago /bin/sh -c mkdir warmup && cd warmup ... 297MB
<missing> 4 weeks ago /bin/sh -c #(nop) ENV NUGET_XMLDOC_MODE=skip 0B
<missing> 4 weeks ago /bin/sh -c curl -SL $DOTNET_SDK_DOWNLOAD_U... 290MB
<missing> 4 weeks ago /bin/sh -c #(nop) ENV DOTNET_SDK_DOWNLOAD... 0B
<missing> 4 weeks ago /bin/sh -c #(nop) ENV DOTNET_SDK_VERSION=... 0B
<missing> 4 weeks ago /bin/sh -c apt-get update && apt-get i... 1.64MB
<missing> 4 weeks ago /bin/sh -c apt-get update && apt-get insta... 123MB
<missing> 4 weeks ago /bin/sh -c apt-get update && apt-get insta... 44.6MB
<missing> 4 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 4 weeks ago /bin/sh -c #(nop) ADD file:f4e6551ac34ab44... 124MB
答案 0 :(得分:2)
我通过更改 build.sh 文件中的最后一行解决了这个问题:
docker push $REPO
到
docker push $REPO:$TAG
我正在将整个存储库推回到每个构建的码头服务器上,而不仅仅是我刚刚创建的图像。每个构建都需要比最后一个构建更长的时间,因为存储库随着添加到其中的每个图像而增长。