<p>I have problem with kubernetes (minikube) and pull images from local image repository on docker.
Docker repository was created:</p>

<pre><code>docker run --entrypoint htpasswd registry:2 -Bbn zordon examplePassword &gt; /mnt/LINUX/auth/htpasswd

docker run -d \
  -p 5000:5000 \
  --restart=always \
  --name registry \
  -v /mnt/LINUX/dockerreg:/var/lib/registry \
  -v /mnt/LINUX/auth:/auth \
  -e "REGISTRY_AUTH=htpasswd" \
  -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
  -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
  registry:2
</code></pre>

<p>Then I want to create simple pod with image which was succesfully uploaded to local repository:</p>

<pre><code>curl localhost:5000/v2/_catalog
{"repositories":["car/configuration"]}
</code></pre>

<p>I have also create secret on minikube cluster with:</p>

<pre><code>kubectl create secret docker-registry docregkey --docker-server=localhost:5000 --docker-username=zordon --docker-password=examplePassword --docker-email=test@dock.mail
</code></pre>

<p>and define simple Pod:</p>

<pre><code>    apiVersion: v1
kind: Pod
metadata:
  name: private-reg
spec:
  containers:
  - name: private-reg-container
    image: car/configuration:latest
    imagePullPolicy: Always
  restartPolicy: Always
  imagePullSecrets:
  - name: docregkey
</code></pre>

<p>unfortunatelly I getting still:</p>

<blockquote>
  <p>Failed to pull image "car/configuration:latest": rpc error: code =
  Unknown desc = Error response from daemon: pull access denied for
  car/configuration, repository does not exist or may require 'docker
  login'</p>
</blockquote>

<p>How i can fix this problem ?</p>

<p>For minikube to pull from your own local docker registry, the tag affects the pull policy. Per <a href="https://kubernetes.io/docs/concepts/containers/images" rel="noreferrer">Images docs</a>, pull policy is <code>IfNotPresent</code> by default EXCEPT if</p>

<ol>
<li>you use <code>:latest</code> as the tag for the image to use</li>
<li>OR you omit the tag for the image to use.</li>
</ol>

<p>In those cases the pull policy will effectively default to <code>Always</code>, which will attempt to pull from docker hub. This will cause minikube to be unable to fetch local images that have no tag or "latest" tag. </p>

<p>Moral of the story is, don't rely on the default because it is too confusing :)</p>

<p>So always explicitly state the pull policy: </p>

<ol>
<li>when deploying into minikube the pull policy should be
<code>IfNotPresent</code> or <code>Never</code> for the local images</li>
<li>when deploying into a cloud host (like AWS), pull policy should be as for public images (see below)</li>
<li>the pull policy should be <code>Always</code> for those public images that use a tag like "latest" or "stable" (because the image the tag
points will change over time), and <code>IfNotPresent</code> for tags that
always point to the same image (to avoid fetching more than
necessary)</li>
</ol>

<p>This means that if you avoid using tags like latest and stable etc, there is only one rule to follow: </p>

<ol>
<li>explicitly set the <code>imagePullPolicy</code> in your spec (or on the command line in the case of run) to <code>IfNotPresent</code>, as this is will always look for it locally first, and go to public registry if it is not found locally, and this will work whether or not you are deploying into minikube or cloud. </li>
</ol>
