<p>I am trying to run docker from my pod to launch docker containers (docker inside k8s). To get docker images from the host I am mounting docker.sock and docker command in my pod through hostPath. Even though I find the files mounted I cannot execute the docker command, it will fail with command not found error.</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: alphine
  labels:
    app: alphine
spec:
  containers:
  - name: alpine
    image: alpine
    securityContext:
      privileged: true
    volumeMounts:
    - name: tmp
      mountPath: /tmp
    - name: docker-sock
      mountPath: /var/run/docker.sock
    - name: docker-cmd  # docker command from host.
      mountPath: /usr/bin/docker
    - name: lib64  # for running docker from the host.
      mountPath: /lib64
      readOnly: true
    - name: usr-lib64  # for running docker from the host.
      mountPath: /usr/lib64
      readOnly: true
    command: [&quot;sleep&quot;, &quot;infinity&quot;]
  volumes:
  - name: tmp
    emptyDir: {}
  - name: docker-cmd
    hostPath:
      path: /usr/bin/docker
      type: File
  - name: lib64
    hostPath:
      path: /lib64
      type: Directory
  - name: usr-lib64
    hostPath:
      path: /usr/lib64
      type: Directory
  - name: docker-sock
    hostPath:
      path: /var/run/docker.sock
      type: Socket
</code></pre>
<p>I am staring minikube with below command</p>
<pre><code>minikube start --memory=16g --cpus=2 --disk-size=10g \
  -p mycluster \
  --extra-config=apiserver.enable-admission-plugins=PodSecurityPolicy \
  --addons=pod-security-policy --wait=all
</code></pre>
<p>The same does work in Docker in Docker environment. Where I will start my container with below command</p>
<pre><code> docker create
      --name=mypod
      --read-only
      --restart=on-failure
      -v /usr/bin/docker:/usr/bin/docker:ro
      -v /lib64:/lib64:ro
      -v /usr/lib64:/usr/lib64:ro
      -v /var/run/docker.sock:/var/run/docker.sock
      alphine

docker start mypod
</code></pre>
<p>Am I missing something here? Any pointers/reference is appreciated. Thanks in Advance.</p>

RandomQuests
<p>The hostPath of your minikube cluster isn't the same as your local machine. When you run the <code>docker</code> command on your local machine, it uses the hostPath of your machine where the files/directory exists. But these files/directories don't exist inside the minkube cluster node.</p>
<p><strong>Solution:</strong></p>
<ol>
<li>Create a Dockerfile and copy the files/directories while building the image:</li>
</ol>
<pre><code>FROM alphine:latest
COPY /var/run/docker.sock /var/run/docker.sock
... ...
... ...
CMD [&quot;sleep&quot;, &quot;infinity&quot;]
</code></pre>
<ol start="2">
<li>Use this image in your pod:</li>
</ol>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: alphine
  labels:
    app: alphine
spec:
  containers:
  - name: your_image
    image: your_image:latest
    securityContext:
      privileged: true
</code></pre>
