0

I'm using RUN ls /some/directory for "printf-debugging" of a Dockerfile. After the command has been run once and no command has changed before, the result is cached and no output is provided.

I can change the command with a part which is never executed, e.g. append || echo some changing number] which is annoying for every run or turn off the build cache which affects more RUNs than necessary and thus slows down the development of the Dockerfile.

Is there a way to disable the cache for just one RUN without any of the described downsides?

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
  • 1
    https://stackoverflow.com/questions/35134713/disable-cache-for-specific-run-commands – Sebastian Brosch Jan 22 '19 at 14:30
  • 1
    @SebastianBrosch Thanks for this better duplicate. I flagged the question I choose as identical to mine as duplicate of the question you linked. I also added comments to the moby issues linked in different answers which seem to be be duplicates of each other. – Kalle Richter Jan 22 '19 at 14:40

1 Answers1

1

Would using a build arg be an acceptable solution?

# Dockerfile
FROM alpine
RUN echo "executed 1"

# Above this will be cached, below will be retriggered with new builds
ARG BUILD

RUN echo "executed 2"

Then, running with different build arg number to re-run everything below the ARG

$ docker build --build-arg BUILD=2 -t temp .

Or, with using date as the build number:

$ docker build --build-arg BUILD="$(date)" -t temp .
DannyB
  • 12,810
  • 5
  • 55
  • 65