Home > Enterprise >  Removed Docker image is reappearing again upon new build command
Removed Docker image is reappearing again upon new build command

Time:07-16

Scenario: I made a working dockerfile, and I want to test them from scratch. However, the remove command only removes the image temporarily, meaning that running build command again will make them reappear as if it was never removed in a first place.

Example:

This is what my terminal looks like: enter image description here

*Note: first two images are irrelevant to this question.

The ***_seis image is removed using docker rmi ***_seis command, and as a result, running docker images will show that ***_seis image was deleted.

However, when I run the following build command:

docker build -f dockerfile -t ***_seis:latest .

It will build successfully, but gives this result: enter image description here

Even though it was removed seconds ago, build took less than a minute and the created date indicates that it was made 3 days ago.

Log:

This is what my build log looks like:

docker build -f dockerfile -t ***_seis:latest .
[ ] Building 11.3s (14/14) FINISHED                                                                                                                                                 
 => [internal] load build definition from dockerfile                                                                                                                           0.0s
 => => transferring dockerfile: 38B                                                                                                                                            0.0s
 => [internal] load .dockerignore                                                                                                                                              0.0s
 => => transferring context: 2B                                                                                                                                                0.0s
 => [internal] load metadata for docker.io/jupyter/base-notebook:latest                                                                                                       11.2s
 => [1/9] FROM docker.io/jupyter/base-notebook:latest@sha256:bc9ad73498f21ae716ba0e58d660063eae1677f6dd2bd5b669248fd0bf22dc79                                                  0.0s
 => [internal] load build context                                                                                                                                              0.0s
 => => transferring context: 32B                                                                                                                                               0.0s
 => CACHED [2/9] RUN apt update &&     apt install --no-install-recommends -y         software-properties-common         git         zip         unzip         wget         v  0.0s
 => CACHED [3/9] RUN conda install -c conda-forge jupyter_contrib_nbextensions jupyter_nbextensions_configurator jupyter-resource-usage                                        0.0s
 => CACHED [4/9] RUN mkdir /home/jovyan/environment_ymls                                                                                                                       0.0s
 => CACHED [5/9] COPY seis.yml /home/jovyan/environment_ymls/seis.yml                                                                                                      0.0s
 => CACHED [6/9] RUN conda env create -f /home/jovyan/environment_ymls/seis.yml                                                                                              0.0s
 => CACHED [7/9] RUN python -m ipykernel install --name seis--display-name "seis"                                                                                         0.0s
 => CACHED [8/9] WORKDIR /home/jovyan/***_seis                                                                                                                             0.0s
 => CACHED [9/9] RUN chown -R jovyan:users /home/jovyan                                                                                                                        0.0s
 => exporting to image                                                                                                                                                         0.0s
 => => exporting layers                                                                                                                                                        0.0s
 => => writing image sha256:16a8e90e47c0adc1c32f28e32ad17a8bc72795c3ca9fc39e792fa383793c3bdb                                                                                   0.0s
 => => naming to docker.io/library/***_seis:latest  

Troubleshooting: So far, I've tried different ways of removing them, such as

docker rmi <image_name>
docker image prune

and manually removing from docker desktop.

I made sure that all containers are deleted by using:

docker ps -a

Expected result: If successful, it should rebuild from scratch, takes longer than a minute to build, and creation date should reflect the time it was actually created.

Question: I would like to know what is the issue here in terms of image not being deleted completely. Why does it recreate image from the past rather than just starting new build?

Thank you in advance for your help.

CodePudding user response:

It's building from the cache. Since no inputs appear to have changed to the build engine, and it has the steps from the previous build, they are reused, including the image creation date.

You can delete the build cache. But I'd recommend instead to run:

docker build --pull --no-cache -f dockerfile -t ***_seis:latest .

The --pull option pulls a new base image should you have an old version pulled locally. And the --no-cache option skips the caching for various steps (in particular a RUN step that may fetch the latest external dependency).

  • Related