<h2>Question</h2>
<p>How to run a local Docker private registry in minikube while using the docker driver? (<code>--driver=docker</code>)</p>
<h2>The issue</h2>
<p><strong>Connection refused</strong> when pushing images to private registry</p>
<pre class="lang-sh prettyprint-override"><code>docker push docker-registry.kubemaster.me/docker-cats:latest

# Results
The push refers to repository [docker-registry.kubemaster.me/docker-cats]
Get http://docker-registry.kubemaster.me/v2/: dial tcp 127.0.0.1:80: connect: connection refused
</code></pre>
<h2>My Setup</h2>
<p>Minikube on Windows WSL2 using <a href="https://minikube.sigs.k8s.io/docs/drivers/docker/" rel="nofollow noreferrer">minikube's docker driver</a>.</p>
<pre class="lang-sh prettyprint-override"><code>minikube start --driver=docker --kubernetes-version=v1.20.2
</code></pre>
<p>I've deployed <a href="https://kubernetes.github.io/ingress-nginx/deploy/" rel="nofollow noreferrer">nginx-ingress-controller</a> which listens on ports 80 and 443. The application is available via both HTTP and HTTPS (using <a href="https://cert-manager.io/docs/installation/kubernetes/" rel="nofollow noreferrer">cert-manager</a> for TLS certificates). And of course, I added <code>127.0.0.1 docker-registry.kubemaster.me</code> to my <code>C:\Windows\System32\drivers\etc\hosts</code> file.</p>
<p><strong>NOTE</strong>: I'm running <code>minikube tunnel</code> in the background, this is why it's possible to communicate with the whole cluster from the host via nginx-ingress-controller.</p>
<h2>Accessing the local registry</h2>
<ul>
<li><p>From the <strong>Windows Host</strong></p>
<p><a href="https://i.stack.imgur.com/Pa4Fz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pa4Fz.png" alt="access-from-windows-host" /></a></p>
</li>
<li><p>From the <strong>WSL2 Ubuntu</strong> guest machine.</p>
<pre class="lang-sh prettyprint-override"><code>curl  http://docker-registry.kubemaster.me/v2/_catalog
</code></pre>
<p><a href="https://i.stack.imgur.com/kfmQV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kfmQV.png" alt="access-from-ubuntu-guest" /></a></p>
</li>
<li><p>From <strong>minikube's docker container</strong></p>
<pre class="lang-sh prettyprint-override"><code>docker exec -it minikube bash
root@minikube:/$ curl  http://docker-registry.kubemaster.me/v2/_catalog
</code></pre>
<p><a href="https://i.stack.imgur.com/t8uM0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t8uM0.png" alt="access-from-minikube-container" /></a></p>
</li>
<li><p>Pushing from <strong>minikube's docker container</strong></p>
<pre class="lang-sh prettyprint-override"><code>docker exec -it minikube bash
root@minikube:/$ docker push docker-registry.kubemaster.me/docker-cats
Using default tag: latest
The push refers to repository [docker-registry.kubemaster.me/docker-cats]
346be19f13b0: Layer already exists 
935f303ebf75: Layer already exists 
0e64bafdc7ee: Pushed 
latest: digest: 
sha256:5403064f94b617f7975a19ba4d1a1299fd584397f6ee4393d0e16744ed11aab1 size: 943
</code></pre>
</li>
</ul>
<h2>YAML - Deployment, Service and Ingress</h2>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    k8s-app: docker-registry
  name: docker-registry
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: docker-registry
  template:
    metadata:
      labels:
        k8s-app: docker-registry
    spec:
      containers:
        - image: registry:2
          imagePullPolicy: Always
          name: docker-registry
          env:
            - name: REGISTRY_HTTP_SECRET
              value: &quot;some-secret&quot;
            - name: REGISTRY_HTTP_ADDR
              value: &quot;0.0.0.0:80&quot;
          ports:
            - containerPort: 80
              hostPort: 80
              protocol: TCP
          resources:
            limits:
              memory: 400Mi
              cpu: &quot;200m&quot;
            requests:
              memory: 200Mi
              cpu: 100m
---
apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: docker-registry
  name: docker-registry
  namespace: kube-system
spec:
  type: LoadBalancer
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 80
  selector:
    k8s-app: docker-registry
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: docker-registry
  namespace: kube-system
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: 2000m # support large images
spec:
  ingressClassName: nginx
  rules:
    - host: docker-registry.kubemaster.me
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              serviceName: docker-registry
              servicePort: 80
</code></pre>
<p>P.S- My setup of how to deploy a local Kubernetes cluster for development purposes - <a href="https://github.com/unfor19/kubernetes-localdev" rel="nofollow noreferrer">https://github.com/unfor19/kubernetes-localdev</a></p>

Meir Gabay
<p>Dropped this idea, instead, I'm using minikube's Docker daemon by executing</p>
<pre class="lang-sh prettyprint-override"><code>eval $(minikube docker-env)
</code></pre>
