October 2, 2022
Docker caches image build results to accelerate subsequent rebuilds. While this mechanism is generally reliable, sometimes you’ll want to rebuild an image without using the cache. This could be to diagnose issues or check the complete build procedure will be reproducible in a clean environment. In this article, you’ll learn how to achieve a fresh…

Docker caches image build results to accelerate subsequent rebuilds. While this mechanism is generally reliable, sometimes you’ll want to rebuild an image without using the cache. This could be to diagnose issues or check the complete build procedure will be reproducible in a clean environment.

In this article, you’ll learn how to achieve a fresh build without manually deleting the cache. You’ll also see how to pull updated base images so your build matches the output that a new Docker installation would produce.

How the Cache Works

Here’s a simple Dockerfile:

FROM alpine:latest COPY 1.txt /1.txt COPY 2.txt /2.txt

Populate the sample files in your working directory and build the image:

$ echo 1 > 1.txt $ echo 2 > 2.txt $ docker build -t demo:latest .

The output will look similar to this:

Sending build context to Docker daemon 5.12kB Step 1/3 : FROM alpine:latest —> 9c6f07244728 Step 2/3 : COPY 1.txt /1.txt —> db61ff73c0b5 Step 3/3 : COPY 2.txt /2.txt —> f1129e47fc12 Successfully built f1129e47fc12 Successfully tagged demo:latest

Now modify 2.txt and then rebuild the image:

$ echo two > 2.txt $ docker build -t demo:latest…

Read Full Article Source

Leave a Reply

Your email address will not be published.