有什么想法吗?为什么我没有成功挂载我的本地目录?感谢您的帮助. 解决方案 看起来解决方案是使用 privilaged container,或手动挂载您的主文件夹以允许 MiniKube VM 从您的主机路径读取 -- https://github.com/boot2docker/boot2docker#virtualbox-guest-additions.(感谢 Eliel 解决了这个问题).绝对可以使用 minikube 配置 hostPath 卷 - 但有很多怪癖,并且对这个特定问题没有很好的支持.尝试从 Dockerfile 中删除 ADD code//code.Docker 的添加"指令正在将代码从您的主机复制到您的容器的 /code 目录.这就是重建映像成功更新代码的原因.当 Kubernetes 尝试将容器的 /code 目录挂载到主机路径时,它发现该目录已经充满了烘焙到映像中的代码.如果您在构建步骤中取消此操作,Kubernetes 应该能够在运行时成功挂载主机路径.还要确保检查主机上code/目录的权限.我唯一的其他想法与在根目录中安装有关.我在将 Kubernetes hostPath 卷安装到/从根目录中的目录安装时遇到问题(我认为这与权限相关).因此,可以尝试使用类似 /var/www/html 的 mountPath.以下是功能性 hostPath 卷的示例:apiVersion: v1种类:豆荚元数据:名称:示例规格:卷:- 名称:示例卷主机路径:路径:'/Users/example-user/code'容器:- 名称:示例容器图像:示例图像卷挂载:- 挂载路径:'/var/www/html'名称:示例卷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 themI try to mount an host directory for developing my app with kubernetes.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.my test app (server.js):var http = require('http');var handleRequest = function(request, response) {response.writeHead(200);response.end("Hello World!");}var www = http.createServer(handleRequest);www.listen(8080);my Dockerfile:FROM node:latestWORKDIR /codeADD code/ /codeEXPOSE 8080CMD server.jsmy pod kubernetes configuration: (pod-configuration.yaml)apiVersion: v1kind: Podmetadata: name: apiserverspec: 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/<myuser>/Projects/nodetest/api-server/codemy folder are:/home/<myuser>/Projects/nodetest/- pod-configuration.yaml- api-server/ - Dockerfile - code/ - server.jsWhen 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.Any idea ? why i don't success to mount my local directory ?Thanks for the help. 解决方案 EDIT: Looks like the solution is to either use a privilaged container, or to manually mount your home folder to allow the MiniKube VM to read from your hostPath -- https://github.com/boot2docker/boot2docker#virtualbox-guest-additions. (Credit to Eliel for figuring this out).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.Try removing ADD code/ /code from your Dockerfile. Docker's "ADD" instruction is copying the code from your host machine into your container's /code directory. This is why rebuilding the image successfully updates your code.When Kubernetes tries to mount the container's /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.Also be sure to check the permissions of the code/ directory on your host machine.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 /var/www/html.Here's an example of a functional hostPath volume:apiVersion: v1kind: Podmetadata: name: examplespec: 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 这篇关于带有 minikube 的 HostPath - Kubernetes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!