Mount local directory into pod in minikube Mount local directory into pod in minikube kubernetes kubernetes

Mount local directory into pod in minikube


You can't mount your local directory into your Pod directly.

First, you need to mount your directory $HOME/go/src/github.com/nginx into your minikube.

$ minikube start --mount-string="$HOME/go/src/github.com/nginx:/data"

Then If you mount /data into your Pod using hostPath, you will get you local directory data into Pod.

There is another way

Host's $HOME directory gets mounted into minikube's /hosthome directory. Here you will get your data

$ ls -la /hosthome/go/src/github.com/nginx

So to mount this directory, you can change your Pod's hostPath

hostPath:  path: /hosthome/go/src/github.com/nginx


I tried out aerokite's solution, but found out that I had to pass --mount as well as --mount-string "local-path:minikube-path" to mount a directory in minikube.

minikube start --mount-string ${HOME}/go/src/github.com/nginx:/data --mount.Spent some time figuring this out.


I found a way.

This way you can directly mount directory to container. You do not have to mount your directory to minikube first.

We can specify the directory we want to add into container by using hostPath in volumes

  volumeMounts:    - name: crypto-config      mountPath: <PATH IN CONTAINER>    - name: channel-artifacts      mountPath: /opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts    - name: chaincode      mountPath: /opt/gopath/src/github.com/chaincode  volumes:    - name: crypto-config      hostPath:        path: <YOUR LOCAL DIR PATH>    - name: channel-artifacts      hostPath:        path: /Users/akshaysood/Blockchain/Kubernetes/Fabric/network/channel-artifacts    - name: chaincode      hostPath:        path: /Users/akshaysood/Blockchain/Kubernetes/Fabric/network/chaincode