How to setup docker to use cache from registry on every build step

后端 未结 3 844
天命终不由人
天命终不由人 2021-02-04 03:57

I have two servers with docker and one server with my private registry.

I built Dockerfile on the first machine; then I pushed the image to the registry.

Is it

3条回答
  •  臣服心动
    2021-02-04 04:21

    For Docker versions >= 19.03, you can use the new BuildKit features to avoid having to pull the remote image before building. Activate BuildKit by setting the DOCKER_BUILDKIT enviroment variable, then turn on inline caching to store the build cache along with your image in your registry using the BUILDKIT_INLINE_CACHE build argument, as follows:

    export DOCKER_BUILDKIT=1
    docker build -t registry/imagename:tag --cache-from registry/imagename:tag --build-arg BUILDKIT_INLINE_CACHE=1 .
    docker push registry/imagename:tag
    

    Thanks to Nicholas Dille for this solution.

提交回复
热议问题