Cache not working when using arguments (RUN $foo)

I have a Dockerfile similar to

ARG os_ver=5
ARG cuda_ver=4.2

COPY install /root/install
#RUN /root/install/  ${os_ver} ${cuda_ver}

# separate RUNs for each part, to speed up development
# use for smaller image for production
RUN /root/install/     	$os_ver
RUN /root/install/  	$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.

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