Docker image in local computer has deleted by Kubernetes garbage collection

1/31/2020

I am working on single node kubernetes cluster built with kubeadm. During development, create a new docker image, but the image will be deleted immediately without permission from kubernetes garbage collection. How do I control this?

Environment:

  • kubeadm version: v1.17.2
  • kubelet version: v1.17.2
  • docker version: 19.03.5
  • Ubuntu 18.04 desktop
  • Linux kernel version: 4.15.0-74-generic
-- MASH
docker
kubernetes

1 Answer

1/31/2020

I created an image with the docker build command on master node, and confirmed that the image was deleted immediately with docker container ls -a. If I running Docker only, the images have not been deleted. So I guess the reason for the removal was due to the kubernetes garbage collection. – MASH 3 hours ago

Honestly, I doubt that your recently build docker image could've been deleted by kubernetes garbage collector.

I think you are confusing two concepts: image and stopped container. If you want to check your local images, you should use docker image ls command, not docker container ls -a. The last one doesn't say anything about available images and doesn't prove that any image was deleted.

It's totally normal behaviour of Docker. Please look at this example from docker docs:

We build a new docker image using following commands:

# create a directory to work in
mkdir example
cd example

# create an example file
touch somefile.txt

# build an image using the current directory as context, and a Dockerfile passed through stdin
docker build -t myimage:latest -f- . <<EOF
FROM busybox
COPY somefile.txt .
RUN cat /somefile.txt
EOF

After successful build:

Sending build context to Docker daemon  2.103kB
Step 1/3 : FROM busybox
 ---> 020584afccce
Step 2/3 : COPY somefile.txt .
 ---> 216f8119a0e6
Step 3/3 : RUN cat /somefile.txt
 ---> Running in 90cbaa24838c
Removing intermediate container 90cbaa24838c
 ---> b1e6c2284368
Successfully built b1e6c2284368
Successfully tagged myimage:latest

we run:

$ docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

As you can see there's nothing there and it's totally ok.

But when you run docker image ls command instead, you'll see our recently build image:

$ docker image ls
REPOSITORY                                TAG                 IMAGE ID            CREATED             SIZE
myimage                                   latest              b1e6c2284368        10 seconds ago      1.22MB
-- mario
Source: StackOverflow