gpt4 book ai didi

docker - 在 CircleCI 中缓存 Docker 镜像

转载 作者:行者123 更新时间:2023-12-04 21:35:21 28 4
gpt4 key购买 nike

我正在使用 CircleCI 运行测试并部署 Docker 镜像,但我在缓存 Docker 镜像时遇到问题,导致构建时间很长。

这是一个不起作用的最小示例:

圆.yml

machine:
services:
- docker

dependencies:
cache_directories:
- "~/docker"
override:
- if [[ -e ~/docker/image.tar ]]; then echo "cached files exists!" ; docker load -i ~/docker/image.tar; fi
- docker images
- docker build -t myorg/myapp:v1.1.1 .
- mkdir -p ~/docker; docker save myorg/myapp:v1.1.1 > ~/docker/image.tar

Dockerfile:
FROM debian:latest
MAINTAINER My Name <myname@gmail.com>
RUN apt-get update && apt-get install -y vim
CMD ["sleep", "3"]

当推送到 GitHub 时,构建在 CircleCI 中运行良好。但是每次运行时都会重新构建 Docker 镜像。这在生产 Docker 镜像中非常耗时。

文件 image.tar 已明确加载,从 docker images 的输出中可以清楚地看出这一点。命令,但它仍然每次都构建整个镜像,即使 Dockerfile 没有改变。

这是 docker build -t myorg/myapp:v1.1.1 . 行的一些输出
docker build -t myorg/myapp:v1.1.1 .
Sending build context to Docker daemon 67.07 kB


Step 1 : FROM debian:latest
latest: Pulling from library/debian


Digest: sha256:370807fef6f790d8519399026d26461bdf8360f94ab450da94c2350bea3cc66d
Status: Downloaded newer image for debian:latest
---> ae85c48b369c
Step 2 : MAINTAINER My Name <myname@gmail.com>
---> Running in 4ffd69c2a82d
---> 6029750ba0f3
Error removing intermediate container 4ffd69c2a82d: rmdriverfs: Driver btrfs failed to remove root filesystem 4ffd69c2a82d644ea7ee8576cc06e67ee412f651edecbc40932394c057aa931d: Failed to destroy btrfs snapshot /var/lib/docker/btrfs/subvolumes for 4ffd69c2a82d644ea7ee8576cc06e67ee412f651edecbc40932394c057aa931d: operation not permitted
Step 3 : RUN apt-get update && apt-get install -y vim
---> Running in 544047b8c170
Ign http://httpredir.debian.org jessie InRelease
Get:1 http://httpredir.debian.org jessie-updates InRelease [142 kB]
Get:2 http://httpredir.debian.org jessie Release.gpg [2373 B]
Get:3 http://httpredir.debian.org jessie Release [148 kB]
Get:4 http://security.debian.org jessie/updates InRelease [63.1 kB]
Get:5 http://httpredir.debian.org jessie-updates/main amd64 Packages [17.6 kB]
Get:6 http://httpredir.debian.org jessie/main amd64 Packages [9064 kB]
Get:7 http://security.debian.org jessie/updates/main amd64 Packages [390 kB]
Fetched 9828 kB in 2s (4030 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
The following extra packages will be installed:
libgpm2 vim-common vim-runtime
Suggested packages:
gpm ctags vim-doc vim-scripts
The following NEW packages will be installed:
libgpm2 vim vim-common vim-runtime
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 6218 kB of archives.
After this operation, 28.9 MB of additional disk space will be used.
Get:1 http://httpredir.debian.org/debian/ jessie/main libgpm2 amd64 1.20.4-6.1+b2 [34.0 kB]
Get:2 http://httpredir.debian.org/debian/ jessie/main vim-common amd64 2:7.4.488-7 [184 kB]
Get:3 http://httpredir.debian.org/debian/ jessie/main vim-runtime all 2:7.4.488-7 [5047 kB]
Get:4 http://httpredir.debian.org/debian/ jessie/main vim amd64 2:7.4.488-7 [953 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 6218 kB in 0s (10.7 MB/s)
Selecting previously unselected package libgpm2:amd64.

知道为什么每次都重建docker镜像吗?

最佳答案

现在您可以在 CircleCI 上启用 docker 层缓存。
这是一项高级功能。它将重用以前用于构建图像的层。

https://circleci.com/docs/2.0/docker-layer-caching/

关于docker - 在 CircleCI 中缓存 Docker 镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39725892/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com