Search code examples
dockercachingdockerfilemountunmount

Unmounting a RUN cache-type mount in a Dockerfile


In a Dockerfile, I am mounting a cache:

RUN  --mount=type=cache,target=/opt/conda/pkgs \
     ...

I would like this mount to be valid for the duration of either

  1. just this RUN command
  2. until it is unmounted a few layers further down

Is there a way to do this?

I'm not able to find any reference in the documentation.


Solution

  • Try making use of the multi stage Dockerfile

    For example :-

    FROM BASE_IMAGE:tag AS base
    RUN  --mount=type=cache,target=/opt/conda/pkgs \
     ...
    
    
    FROM BASE_IMAGE:tag AS app
    RUN mkdir /some/place
    COPY --from=base "/opt/conda/pkgs"