<p>I try to run my private docker image along with the <strong>docker-dind</strong> container to be able to run docker commands from the private image in Kubernetes.
My only issue is that the <code>docker run</code> command does not read the docker-secrets so fails by requiring to run <code>docker login</code>. How could I pass the credentials to the docker run command?</p>
<p>Here the piece of my Kubernetes deployment:</p>
<pre><code>  containers:
    - name: docker-private
      image: docker:20.10
      command: ['docker', 'run', '-p', '80:8000', 'private/image:latest' ]
      resources:
        requests:
          cpu: 10m
          memory: 256Mi
      env:
        - name: DOCKER_HOST
          value: tcp://localhost:2375
      envFrom:
         - secretRef:
             name: docker-secret-keys
    - name: dind-daemon
      image: docker:20.10-dind
      command: [&quot;dockerd&quot;, &quot;--host&quot;, &quot;tcp://127.0.0.1:2375&quot;]
      resources:
        requests:
          cpu: 20m
          memory: 512Mi
      securityContext:
        privileged: true
      volumeMounts:
        - name: docker-graph-storage
          mountPath: /var/lib/docker
</code></pre>
<p><strong>EDIT</strong>
I do have my certificate as Kubernetes secrets that I try to mount to the running docker but until now without any success :(</p>
<pre><code>apiVersion: v1
data:
  .dockerconfigjson: eyJhXXXXXXdoihfc9w8fwpeojfOFwhfoiuwehfo8wfhoi2ehfioewNlcm5hbWUiOiJlbGRhcmVudGas4hti45ytg45hgiVsZGFXXXXXXyQGVudG9yLmlvIiwiYXV0aCI6IlpXeGtZWEpsYm5SdmNqb3dObVl4WmpjM1lTMDVPRFZrTFRRNU5HRXRZVEUzTXkwMk5UYzBObVF4T0RjeFpUWT0ifX19XXXXXXXXXXX
kind: Secret
metadata:
  name: staging-docker-keys
  namespace: staging
  resourceVersion: &quot;6383&quot;
  uid: a7yduyd-xxxx-xxxx-xxxx-ae2ede3e4ed
type: kubernetes.io/dockerconfigjson
</code></pre>
<p>The final goal is to get the &quot;inner docker&quot; (that runs private/image:latest) be able to run any docker command without a need to login before each command.</p>

<p>docker:dind will create ca, server, client cert in <code>/certs</code>.
Just create <code>emptyDir</code> volume to share cert.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: myapp
  labels:
    name: myapp
spec:
  volumes:
  - name: docker-tls-certdir
    emptyDir: {}
  containers:
    - name: docker-private
      image: docker:20.10
      command: ['docker', 'run', '-p', '80:8000', 'nginx' ]
      env:
        - name: DOCKER_HOST
          value: tcp://localhost:2375
      volumeMounts:
        - name: docker-tls-certdir
          mountPath: /certs
    - name: dind-daemon
      image: docker:20.10-dind
      command: [&quot;dockerd&quot;, &quot;--host&quot;, &quot;tcp://127.0.0.1:2375&quot;]
      securityContext:
        privileged: true
      volumeMounts:
        - name: docker-tls-certdir
          mountPath: /certs
</code></pre>
