<p>If I want to run a container <code>B</code> within a container <code>A</code> (reusing the Docker daemon) I can just bind mount <code>/var/run/docker.sock</code> and <code>/usr/bin/docker</code> and can happily call <code>docker run</code> within <code>A</code>.
Now I would like to share a k8s volume between <code>A</code> and <code>B</code>. For that I thought of creating an emptyDir volume in <code>A</code> and pass it to <code>B</code> using <code>docker run -v</code>. But this does not work as the emptyDir volume does not seem to be a Docker volume (it does not appear when running <code>docker volume ls</code>).</p>

<p>The snippet below prints a list of volume where <code>cache-volume</code> does not appear:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: alpine
    name: test-container
    command: [ash]
    args: ["-c", "docker volume ls"]
    volumeMounts:
    - name: dockersock
      mountPath: "/var/run/docker.sock"
    - name: dockerlib
      mountPath: "/usr/bin/docker"
    - name: cache-volume
      mountPath: /cache
  volumes:
  - name: dockersock
    hostPath:
      path: /var/run/docker.sock
  - name: dockerlib
    hostPath:
      path: /usr/bin/docker
  - name: cache-volume
    emptyDir: {}
</code></pre>

<p>So the question is: is there any way to define a volume usable both in k8s and docker?</p>

stackoverflowed
<p>For the record I found a workaround but if you have a better suggestion please don't hesitate to share it.</p>

<p>A solution to the problem above is to mount a hostPath directory <code>D</code> and bind mount this directory into the container <code>B</code>.</p>

<p><code>
apiVersion: v1
kind: Pod
metadata:
  name: test-pd3
spec:
  containers:
  - image: alpine
    name: test-container
    command: [ash]
    args: ["-c", "echo blabla &gt; /home/test.txt ; docker run -v /home:/home --entrypoint ls alpine /home"]
    volumeMounts:
    - name: dockersock
      mountPath: "/var/run/docker.sock"
    - name: dockerlib
      mountPath: "/usr/bin/docker"
    - name: home
      mountPath: "/home"
  volumes:
  - name: dockersock
    hostPath:
      path: /var/run/docker.sock
  - name: dockerlib
    hostPath:
      path: /usr/bin/docker
  - name: home
    hostPath:
      path: /home
</code></p>

<p>The result of the above snippet is that <code>B</code> now has a <code>/home/test.txt</code>, which is what we wanted.</p>
