0

I know this question has been asked over and over. I tried to understand by myself but it is a dead-end. Tell me if this situation is a green or red light.

This is my case on Red Hat Enterprise Linux release 8.4 host:

$ docker --version
$ Docker version 20.10.7, build f0df350

This is no container:

$ docker container ls -a -q
$

There is no image:

$ docker image ls -a -q
$

This is the Dockerfile:

ARG LINUX_FLAVOUR=oraclelinux
ARG LINUX_VERSION=8-slim
FROM ${LINUX_FLAVOUR}:${LINUX_VERSION} as stage_0
EXPOSE 80
CMD ["/bin/bash"]

This the is docker command I am using to build the image:

$ docker build -t test:latest \
> --no-cache=true \
> --rm=true \
> --build-arg LINUX_FLAVOUR=oraclelinux \
> --build-arg LINUX_VERSION=8-slim \
> .
Sending build context to Docker daemon  20.99kB
Step 1/5 : ARG LINUX_FLAVOUR=oraclelinux
Step 2/5 : ARG LINUX_VERSION=8-slim
Step 3/5 : FROM ${LINUX_FLAVOUR}:${LINUX_VERSION} as stage_0
8-slim: Pulling from library/oraclelinux
c828c776e142: Pull complete
Digest: sha256:2c2b8a09e152516dc9c1fef1d437eafe8ac8faeb03a90aaa0b953ce5932f087a
Status: Downloaded newer image for oraclelinux:8-slim
 ---> 6cba6bf8e3bf
Step 4/5 : EXPOSE 80
 ---> Running in ceb30a87b5a6
Removing intermediate container ceb30a87b5a6
 ---> d6b8f86853e6
Step 5/5 : CMD ["/bin/bash"]
 ---> Running in e6180b67d552
Removing intermediate container e6180b67d552
 ---> 931a5da4ce60
Successfully built 931a5da4ce60
Successfully tagged test:latest
$

Docker created the following images:

$ docker image ls -a
REPOSITORY    TAG       IMAGE ID       CREATED              SIZE
test          latest    931a5da4ce60   About a minute ago   111MB
<none>        <none>    d6b8f86853e6   About a minute ago   111MB
oraclelinux   8-slim    6cba6bf8e3bf   3 days ago           111MB
$

This no dangling image:

$ docker images -f "dangling=true" -q
$

The none image cannot be removed:

$ docker image rm -f d6b8f86853e6
Error response from daemon: conflict: unable to delete d6b8f86853e6 (cannot be forced) - image has dependent child images
$

Docker prune command does not work:

$ yes | docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] Total reclaimed space: 0B

$ docker image ls -a
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
test          latest    931a5da4ce60   9 minutes ago   111MB
<none>        <none>    d6b8f86853e6   9 minutes ago   111MB
oraclelinux   8-slim    6cba6bf8e3bf   3 days ago      111MB
$

The none image has indeed a child:

$ docker images --filter since=d6b8f86853e6
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
test         latest    931a5da4ce60   6 minutes ago   111MB
$

So, what did I miss here?

Cyryl1972
  • 594
  • 3
  • 6
  • 1
    They are intermediate layers; if you look at `docker history test` you will probably see them. You can't delete them without deleting the final image, but if you do `docker rmi test` they'll go away. The actual short answer here is to not use the `docker images -a` option, since it shows these intermediate layers but there's nothing you can do with them. – David Maze Jul 16 '21 at 11:23
  • @David you are right of course (confirmed by the official documentation I am reading) – Cyryl1972 Jul 16 '21 at 13:37

0 Answers0