Home > Mobile >  Where does "docker images" look when outputting a list of images
Where does "docker images" look when outputting a list of images

Time:12-07

A word of warning, this is my first posting, and I am new to docker and Kubernetes with enough knowledge to get me into trouble. I am confused about where docker container images are being stored and listing images.

To illustrate my confusion I start with the confirmation that "docker images" indicates no image for nginx is present. Next I create a pod running nginx.

kubectl run nginx --image=nginx is succesful in pulling image "nginx" from github (or that's my assumption):

    Events:
      Type    Reason     Age   From               Message
      ----    ------     ----  ----               -------
      Normal  Scheduled  8s    default-scheduler  Successfully assigned default/nginx to minikube
      Normal  Pulling    8s    kubelet            Pulling image "nginx"
      Normal  Pulled     7s    kubelet            Successfully pulled image "nginx" in 833.30993ms
      Normal  Created    7s    kubelet            Created container nginx
      Normal  Started    7s    kubelet            Started container nginx 

Even though the above output indicates the image is pulled, issuing "docker images" does not include nginx the output.

If I understand correctly, when an image is pulled, it is being stored on my local disk. In my case (Linux) in /var/lib/docker.

So my first question is, why doesn't docker images list it in the output, or is the better question where does docker images look for images?

Next if I issue a docker pull for nginx it is pulled from what I assume to be Github. docker images now includes it in it's output.

Just for my clarification, nothing up to this point involves a private local registry, correct?

I purposefully create a basic local Docker Registry using the docker registry container thinking it would be clearer since that will allow me to explicitly specify a registry but this only results in another issue:

docker run -d \
    -p 5000:5000 \
    --restart=always \
    --name registry \
    -v /registry:/var/lib/registry \
    registry

I tag and push the nginx image to my newly created local registry:

docker tag nginx localhost:5000/nginx:latest
docker push localhost:5000/nginx:latest

The push refers to repository [localhost:5000/nginx]
2bed47a66c07: Pushed
82caad489ad7: Pushed
d3e1dca44e82: Pushed
c9fcd9c6ced8: Pushed
0664b7821b60: Pushed
9321ff862abb: Pushed
latest: digest: sha256:4424e31f2c366108433ecca7890ad527b243361577180dfd9a5bb36e828abf47 size: 1570

I now delete the original nginx image:

docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:9522864dd661dcadfd9958f9e0de192a1fdda2c162a35668ab6ac42b465f0603

... and the newely tagged one:

docker rmi localhost:5000/nginx
Untagged: localhost:5000/nginx:latest
Untagged: localhost:5000/nginx@sha256:4424e31f2c366108433ecca7890ad527b243361577180dfd9a5bb36e828abf47
Deleted: sha256:f652ca386ed135a4cbe356333e08ef0816f81b2ac8d0619af01e2b256837ed3e

... but from where are they being deleted? Now the image nginx should only be present in localhost:5000/? But docker images doesn't show it in it's output.

Moving on, I try to create the nginx pod once more using the image pushed to localhost:5000/nginx:latest.

kubectl run nginx --image=localhost:5000/nginx:latest --image-pull-policy=IfNotPresent

This is the new issue. The connection to localhost:5000 is refused.

    Events:
      Type    Reason     Age   From               Message
      ----    ------     ----  ----               ------- 
      Normal   Pulling    1s    kubelet            Pulling image "localhost:5000/nginx:latest"
      Warning  Failed     1s    kubelet            Failed to pull image "localhost:5000/nginx:latest": rpc error: code = Unknown desc = Error response from daemon: Get "http://localhost:5000/v2/": dial tcp 127.0.0.1:5000: connect: connection refused
      Warning  Failed     1s    kubelet            Error: ErrImagePull
      Normal   BackOff    0s    kubelet            Back-off pulling image "localhost:5000/nginx:latest"

Why is it I can pull and push to localhost:5000, but pod creation fails with what appears to be an authorization issue? I try logging into the registry but no matter what I use for the username and user password, login is successful. This confuses me more. I would try creating/specifying imagePullSecret, but based on docker login outcome, it doesn't make sense.

Clearly I not getting it. Someone please have pity on me and show where I have lost my way.

CodePudding user response:

I will try to bring some clarity to you despite the fact your question already contains about 1000 questions (and you'll probably have 1000 more after my answer :D)

Before you can begin to understand any of this, you need to learn a few basic things:

  1. Docker produces images which are used by containers - it similar to Virtual Machine, but more lightweight (I'm oversimplifying, but the TL;DR is pretty much that).

  2. Kubernetes is an orchestration tool - it is responsible for starting containers (by using already built images) and tracking their state (i.e. if this container has crashed it should be restarted, or if it's not started it should be started, etc)

Docker can run on any machine. To be able to start a container you need to build an image first. The image is essentially a lightweight mini OS (i.e. alpine, ubuntu, windows, etc) which is configured with only those dependencies you need to run your application. This image is then pushed to a public repository/registry (hub.docker.com) or to a private one. And afterwards it's used for starting containers.

Kubernetes builds on top of this and adds the "automation" layer which is responsible for scheduling and monitoring the containers. For example, you have a group of 10 servers all running nginx. One of those servers restarts - the nginx container will be automatically started by k8s.

A kubernetes cluster is the group of physical machines that are dedicated to the mentioned logical cluster. These machines have labels or tags which define the purpose of physical node and work as a constraint for where a container will be scheduled.

Now that I have explained the minimum basics in an oversimplified way I can move with answering your questions.

  1. When you do docker run nginx - you are instructing docker to pull the nginx image from crictl images

    skopeo list-tags

  • Related