Docker Community Forums

Share and learn in the Docker community.

Cache not working when using arguments (RUN script.sh $foo)

build

(Mstormo) #1

I have a Dockerfile similar to

ARG os_ver=5
ARG cuda_ver=4.2

COPY install /root/install
#RUN /root/install/install_all.sh  ${os_ver} ${cuda_ver}

# separate RUNs for each part, to speed up development
# use install_all.sh for smaller image for production
RUN /root/install/install_packages.sh     	$os_ver
RUN /root/install/install_devtoolsets.sh  	$os_ver
...

However, even with the separated script executions in the latter part, the cache won’t work, so it always builds the full image. If I replace the variables with fixed arguments, the cache works.

Obviously, all arguments should be resolved for the cache, so it can save you effort when developing a docker file.


(Mstormo) #2

Apparently not. Copy is copying new files, which invalidates it’s cache entry, so everything following is also invalidated.