<p>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.</p>
<p>To illustrate my confusion I start with the confirmation that &quot;docker images&quot; indicates no image for nginx is present.
Next I create a pod running nginx.</p>
<p><code>kubectl run nginx --image=nginx</code> is succesful in pulling image &quot;nginx&quot; from github (or that's my assumption):</p>
<pre><code>    Events:
      Type    Reason     Age   From               Message
      ----    ------     ----  ----               -------
      Normal  Scheduled  8s    default-scheduler  Successfully assigned default/nginx to minikube
      Normal  Pulling    8s    kubelet            Pulling image &quot;nginx&quot;
      Normal  Pulled     7s    kubelet            Successfully pulled image &quot;nginx&quot; in 833.30993ms
      Normal  Created    7s    kubelet            Created container nginx
      Normal  Started    7s    kubelet            Started container nginx 
</code></pre>
<p>Even though the above output indicates the image is pulled, issuing &quot;docker images&quot; does not include <code>nginx</code> the output.</p>
<p>If I understand correctly, when an image is pulled, it is being stored on my local disk. In my case (Linux) in <code>/var/lib/docker</code>.</p>
<p>So my first question is, why doesn't <code>docker images</code> list it in the output, or is the better question where does <code>docker images</code> look for images?</p>
<p>Next if I issue a <code>docker pull</code> for <code>nginx</code> it is pulled from what I assume to be Github. <code>docker images</code> now includes it in it's output.</p>
<p>Just for my clarification, nothing up to this point involves a private local registry, correct?</p>
<p>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:</p>
<pre class="lang-shell prettyprint-override"><code>docker run -d \
    -p 5000:5000 \
    --restart=always \
    --name registry \
    -v /registry:/var/lib/registry \
    registry
</code></pre>
<p>I tag and push the <code>nginx</code> image to my newly created local registry:</p>
<pre class="lang-shell prettyprint-override"><code>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
</code></pre>
<p>I now delete the original <code>nginx</code> image:</p>
<pre><code>docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:9522864dd661dcadfd9958f9e0de192a1fdda2c162a35668ab6ac42b465f0603
</code></pre>
<p>... and the newely tagged one:</p>
<pre><code>docker rmi localhost:5000/nginx
Untagged: localhost:5000/nginx:latest
Untagged: localhost:5000/nginx@sha256:4424e31f2c366108433ecca7890ad527b243361577180dfd9a5bb36e828abf47
Deleted: sha256:f652ca386ed135a4cbe356333e08ef0816f81b2ac8d0619af01e2b256837ed3e
</code></pre>
<p>... but from where are they being deleted?
Now the image <code>nginx</code> should only be present in localhost:5000/? But <code>docker images</code> doesn't show it in it's output.</p>
<p>Moving on, I try to create the nginx pod once more using the image pushed to <code>localhost:5000/nginx:latest</code>.</p>
<pre><code>kubectl run nginx --image=localhost:5000/nginx:latest --image-pull-policy=IfNotPresent
</code></pre>
<p>This is the new issue. The connection to localhost:5000 is refused.</p>
<pre><code>    Events:
      Type    Reason     Age   From               Message
      ----    ------     ----  ----               ------- 
      Normal   Pulling    1s    kubelet            Pulling image &quot;localhost:5000/nginx:latest&quot;
      Warning  Failed     1s    kubelet            Failed to pull image &quot;localhost:5000/nginx:latest&quot;: rpc error: code = Unknown desc = Error response from daemon: Get &quot;http://localhost:5000/v2/&quot;: dial tcp 127.0.0.1:5000: connect: connection refused
      Warning  Failed     1s    kubelet            Error: ErrImagePull
      Normal   BackOff    0s    kubelet            Back-off pulling image &quot;localhost:5000/nginx:latest&quot;
</code></pre>
<p>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 <code>imagePullSecret</code>, but based on docker login outcome, it doesn't make sense.</p>
<p>Clearly I not getting it.
Someone please have pity on me and show where I have lost my way.</p>

RoyalCoachman
<p>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)</p>
<p>Before you can begin to understand any of this, you need to learn a few basic things:</p>
<ol>
<li><p>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).</p>
</li>
<li><p>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)</p>
</li>
</ol>
<p>Docker can run on any machine. To be able to start a <code>container</code> 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.</p>
<p>Kubernetes builds on top of this and adds the &quot;automation&quot; layer which is responsible for scheduling and monitoring the containers. For example, you have a group of 10 servers all running <code>nginx</code>. One of those servers restarts - the <code>nginx</code> container will be automatically started by k8s.</p>
<p>A kubernetes cluster is the group of physical machines that are dedicated to the mentioned logical cluster. These machines have <code>labels</code> or <code>tags</code> which define the purpose of physical node and work as a constraint for where a container will be scheduled.</p>
<p>Now that I have explained the minimum basics in an oversimplified way I can move with answering your questions.</p>
<ol>
<li><p>When you do <code>docker run nginx</code> - you are instructing docker to pull the <code>nginx</code> image from <a href="https://hub.docker.com/_/nginx" rel="nofollow noreferrer">https://hub.docker.com/_/nginx</a> and then start it on the machine you executed the command on (usually your local machine).</p>
</li>
<li><p>When you do <code>kubectl run nginx --image=nginx</code> - you are instructing Kubernetes to do something similar to <code>1.</code> but in a cluster. The container will be deployed to a <code>random</code> machine somewhere in the cluster unless you put a <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector" rel="nofollow noreferrer">nodeSelector</a> or configure <a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/" rel="nofollow noreferrer">affinity</a>. If you put a <code>nodeSelector</code> this container (called Pod in K8S) will be placed on that specific <code>node</code>.</p>
</li>
<li><p>You have started a <code>private registry</code> server on your local machine. It is crucial to know that <code>localhost</code> inside a <code>container</code> will point to the <code>container</code> itself.</p>
</li>
<li><p>It is worth mentioning that some of the <code>kubernetes</code> commands will create their own <code>container</code> for the execution phase of the command. (remember this!)</p>
</li>
<li><p>When you run <code>kubectl run nginx --image=nginx</code> everything works fine, because it is downloading the image from <code>https://hub.docker.com/_/nginx</code>.</p>
</li>
<li><p>When you run <code>kubectl run nginx --image=localhost:5000/nginx</code> you are telling kubernetes to instruct docker to look for the image at <code>localhost</code> which is ambiguous because you have multiple layers of <code>containers</code> running (check 4.). This means the command that will do <code>docker pull localhost:5000/nginx</code> also runs in a docker container -- so there is no service running at port <code>:5000</code> (the registry is running in a completely different isolated container!) :D</p>
</li>
<li><p>And this is why you are getting <code>Error: ErrImagePull</code> - it can't resolve <code>localhost</code> as it points to itslef.</p>
</li>
<li><p>As for the <code>docker rmi nginx</code> and <code>docker rmi localhost:5000/nginx</code> commands - by running them you removed your <code>local copy</code> of the <code>nginx</code> images.</p>
</li>
<li><p>If you run <code>docker run localhost:5000/nginx</code> on the machine where you started <code>docker run registry</code> you should get a running nginx container.</p>
</li>
</ol>
<p>You should definitely read the <a href="https://docs.docker.com/get-docker/" rel="nofollow noreferrer">Docker Guide</a> <strong>BEFORE</strong> you try to dig into Kubernetes or nothing will ever make sense.</p>
<p>Your head will stop hurting after that I promise... :D</p>
