By default, when we build an image, Docker will try to use the cached layers so that it takes less time to build. However, at times, it is necessary to build from scratch. For example, you will need to force a system update, such as the yum -y update. Let's see how we can do that in this recipe.
Building images without using cached layers
Getting ready
Get a Dockerfile to build the image. For this example, we will be using the following Dockerfile, which installs the nginx web server in an Alpine Linux container:
FROM alpine:3.8
RUN apk add --update nginx && mkdir /tmp/nginx && rm -rf /var/cache/apk/*
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]