How to force Docker for a clean build of an image How to force Docker for a clean build of an image docker docker

How to force Docker for a clean build of an image


There's a --no-cache option:

docker build --no-cache -t u12_core -f u12_core .

In older versions of Docker you needed to pass --no-cache=true, but this is no longer the case.


In some extreme cases, your only way around recurring build failures is by running:

docker system prune

The command will ask you for your confirmation:

WARNING! This will remove:    - all stopped containers    - all volumes not used by at least one container    - all networks not used by at least one container    - all images without at least one container associated to themAre you sure you want to continue? [y/N]

This is of course not a direct answer to the question, but might save some lives... It did save mine.


The command docker build --no-cache . solved our similar problem.

Our Dockerfile was:

RUN apt-get updateRUN apt-get -y install php5-fpm

But should have been:

RUN apt-get update && apt-get -y install php5-fpm

To prevent caching the update and install separately.

See: Best practices for writing Dockerfiles