我正在尝试实现Buildkit 的缓存挂载功能。
我的 Dockerfile 是:
# syntax = docker/dockerfile:experimental
FROM python:3.6-alpine
RUN --mount=type=cache,target=/root/.cache/pip pip install pyyaml
命令:docker build --progress=plain -t abc:1 . --no-cache
首次运行输出:
#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.0s
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 175B done
#1 DONE 0.0s
#3 resolve image config for docker.io/docker/dockerfile:experimental
#3 DONE 2.8s
#4 docker-image://docker.io/docker/dockerfile:experimental@sha256:787107d7f...
#4 CACHED
#5 [internal] load metadata for docker.io/library/python:3.6-alpine
#5 DONE 0.0s
#6 [stage-0 1/2] FROM docker.io/library/python:3.6-alpine
#6 CACHED
#7 [stage-0 2/2] RUN --mount=type=cache,target=/root/.cache/pip pip install...
#7 1.410 Collecting pyyaml
#7 1.731 Downloading PyYAML-5.3.1.tar.gz (269 kB)
#7 2.470 Building wheels for collected packages: pyyaml
#7 2.471 Building wheel for pyyaml (setup.py): started
#7 2.801 Building wheel for pyyaml (setup.py): finished with status 'done'
#7 2.802 Created wheel for pyyaml: filename=PyYAML-5.3.1-cp36-cp36m-linux_x86_64.whl size=44621 sha256=0bfa8470e677b8c2e1d50f8749aa5890b5fb7d7d15352596fbd928c846f9922d
#7 2.802 Stored in directory: /root/.cache/pip/wheels/e5/9d/ad/2ee53cf262cba1ffd8afe1487eef788ea3f260b7e6232a80fc
#7 2.803 Successfully built pyyaml
#7 2.835 Installing collected packages: pyyaml
#7 2.882 Successfully installed pyyaml-5.3.1
#7 DONE 3.3s
#8 exporting to image
#8 exporting layers
#8 exporting layers 0.1s done
#8 writing image sha256:d7ecd86c64611e14f55fa2d31b8f440246e356026eef7175526ccc921373c205 done
#8 naming to docker.io/library/abc:1 done
#8 DONE 0.1s
第二次运行输出:
#1 [internal] load .dockerignore
#1 transferring context: 2B done
#1 DONE 0.0s
#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 37B done
#2 DONE 0.0s
#3 resolve image config for docker.io/docker/dockerfile:experimental
#3 DONE 2.7s
#4 docker-image://docker.io/docker/dockerfile:experimental@sha256:787107d7f...
#4 CACHED
#5 [internal] load metadata for docker.io/library/python:3.6-alpine
#5 DONE 0.0s
#6 [stage-0 1/2] FROM docker.io/library/python:3.6-alpine
#6 CACHED
#7 [stage-0 2/2] RUN --mount=type=cache,target=/root/.cache/pip pip install...
#7 1.385 Collecting pyyaml
#7 1.773 Downloading PyYAML-5.3.1.tar.gz (269 kB)
#7 2.517 Building wheels for collected packages: pyyaml
#7 2.518 Building wheel for pyyaml (setup.py): started
#7 2.844 Building wheel for pyyaml (setup.py): finished with status 'done'
#7 2.846 Created wheel for pyyaml: filename=PyYAML-5.3.1-cp36-cp36m-linux_x86_64.whl size=44621 sha256=064a160d2f195ad7753fba5abf9481b40b515fadffc94f30aef20146209a0faa
#7 2.846 Stored in directory: /root/.cache/pip/wheels/e5/9d/ad/2ee53cf262cba1ffd8afe1487eef788ea3f260b7e6232a80fc
#7 2.846 Successfully built pyyaml
#7 2.877 Installing collected packages: pyyaml
#7 2.920 Successfully installed pyyaml-5.3.1
#7 DONE 3.3s
#8 exporting to image
#8 exporting layers
#8 exporting layers 0.1s done
#8 writing image sha256:42525b426b00a8728b735c15efb96bd237fc020f46d6d99f5bfebb7758016e71 done
#8 naming to docker.io/library/abc:1 done
#8 DONE 0.1s
预期的:
在第二次运行中,我期待pyyaml
从缓存中被选中。
操作系统:Mac OS Catalina (10.15.3)
码头工人版本: