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

后端 未结 3 847
天命终不由人
天命终不由人 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:39

    Note: issue 20316 ("Pulling build cache") has been closed because PR 26839 ("Implement build cache based on history array") has been merged.

    It allows for instance to specify in --cache-from the image from a previous CI build.

    Adds capability to specify images used as a cache source on build. These images do not need to have local parent chain and can be pulled from other registries. User needs to make sure to only use trusted images as sources.

    Usage:

    docker pull myimage:v1.0
    docker build --cache-from myimage:v1.0 -t myimage:v1.1 .
    

    See merge commit 7944480, for docker 1.13 (January 2017).

    As commented by javipolo:

    In case someone is going nuts with reusing layers as I did, the "trick" is to pass to --cache-from the image you are rebuilding (and have it pulled already) and ALSO the image that it uses as base in the FROM.

    Example:
    Dockerfile for image custom-gource:0.1

    FROM base_image:2.2.1
    RUN apt-get update && apt-get install gource
    COPY myscript.sh /myscript.sh
    

    In order to rebuild in other host without doing the apt-get again, you'll need to:

    docker pull custom-gource:0.1
    docker build --cache-from=base_image:2.2.1,custom-gource:0.1 . -t custom-gource:0.2
    

    It might seem too obvious but I've been struggling long time with this until I got that you need to include the base image too

提交回复
热议问题