let's supposse I have a Dockerfile like this:
FROM debian:stretch
RUN apt update
RUN apt install -y wget
RUN wget https://stackoverflow.com/
# I know the wget is useless. Is just an example :)
CMD ["echo", "hello-world"]
I want to put over the wget statement, a new RUN statement. After this change, when I rebuild, It will re-run all the commands from my modification to down, so the wget will be executed again. The problem is that the wget command takes so much time to finish because on my real file, the file is a very big file.
The question is, can be docker "tweaked" somewhere in order to avoid on building the execution again of the wget layer? If I already built it, can that layer be used again even changing a statement over it?
Thank you.
AFAIK this is not possible, as docker only reuses the layers up until your change and starts to build again from there on out.
This is because the new layers get tested on the previously built layers (so your RUN wget
layer is tested and built on the layers from FROM
to RUN apt install -y wget
). So if you'd enter another RUN
instruction above the RUN wget
instruction, you'd get a changed environment for your RUN wget
instruction, so it needs to be executed again.
I don't think there's a way to fidget with it manually so it would reuse the layer built on a "different" environment and neither would I recommend it.