<p>UPDATE:
I connected to the minikubevm and I see my host directory mounted but there is no files there. Also when I create a file there it will not in my host machine. Any link are between them</p>

<p>I try to mount an host directory for developing my app with kubernetes.</p>

<p>As the doc recommended, I am using minikube for running my kubernetes cluster on my pc. The goal is to create a develop environment with docker and kubernetes for develop my app. I want to mount a local directory so my docker will read the code app from there. But it is not work. Any help would be really appreciate.</p>

<p>my test app (server.js):</p>

<pre><code>var http = require('http');
var handleRequest = function(request, response) {
response.writeHead(200);
response.end("Hello World!");
}
var www = http.createServer(handleRequest);
www.listen(8080);
</code></pre>

<p>my Dockerfile:</p>

<pre><code>FROM node:latest
WORKDIR /code
ADD code/ /code
EXPOSE 8080
CMD server.js
</code></pre>

<p>my pod kubernetes configuration: (pod-configuration.yaml)</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: apiserver
spec:
  containers:
  - name: node
    image: myusername/nodetest:v1
    ports:
    - containerPort: 8080
    volumeMounts:
    - name: api-server-code-files
      mountPath: /code
  volumes:
  - name: api-server-code-files
    hostPath:
      path: /home/&lt;myuser&gt;/Projects/nodetest/api-server/code
</code></pre>

<p>my folder are:</p>

<pre><code>/home/&lt;myuser&gt;/Projects/nodetest/
- pod-configuration.yaml
- api-server/
    - Dockerfile
    - code/
        - server.js
</code></pre>

<p>When I running my docker image without the hostPath volume it is of course works but the problem is that on each change I will must recreate my image that is really not powerful for development, that's why I need the volume hostPath.</p>

<p>Any idea ? why i don't success to mount my local directory ?</p>

<p>Thanks for the help.</p>

<p>EDIT: Looks like the solution is to either use a <a href="http://kubernetes.io/docs/user-guide/pods/#privileged-mode-for-pod-containers" rel="noreferrer">privilaged container</a>, or to manually mount your home folder to allow the MiniKube VM to read from your hostPath -- <a href="https://github.com/boot2docker/boot2docker#virtualbox-guest-additions" rel="noreferrer">https://github.com/boot2docker/boot2docker#virtualbox-guest-additions</a>. (Credit to Eliel for figuring this out).</p>

<p>It is absolutely possible to configure a hostPath volume with minikube - but there are a lot of quirks and there isn't very good support for this particular issue.</p>

<p>Try removing <code>ADD code/ /code</code> from your Dockerfile. <a href="https://docs.docker.com/engine/reference/builder/#/add" rel="noreferrer">Docker's "ADD" instruction</a> is copying the code from your host machine into your container's <code>/code</code> directory. This is why rebuilding the image successfully updates your code.</p>

<p>When Kubernetes tries to mount the container's <code>/code</code> directory to the host path, it finds that this directory is already full of the code that was baked into the image. If you take this out of the build step, Kubernetes should be able to successfully mount the host path at runtime.</p>

<p>Also be sure to check the permissions of the <code>code/</code> directory on your host machine.</p>

<p>My only other thought is related to mounting in the root directory. I had issues when mounting Kubernetes hostPath volumes to/from directories in the root directory (I assume this was permissions related). So, something else to try would be a mountPath like <code>/var/www/html</code>.</p>

<p>Here's an example of a functional hostPath volume:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: example
spec:
  volumes:
    - name: example-volume
      hostPath:
        path: '/Users/example-user/code'
  containers:
    - name: example-container
      image: example-image
      volumeMounts:
        - mountPath: '/var/www/html'
          name: example-volume
</code></pre>
