无法在Linux上使用Docker Desktop装载hostPath



我需要用Docker Desktop Kubernetes将一个现有的本地目录挂载到一个pod中,我使用这个yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 1
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: my-image:latest
resources:
limits:
memory: "0"
cpu: "0"
ports:
- containerPort: 80
volumeMounts:
- name: api-code
mountPath: /opt/app/api
volumes:
- name: api-code
hostPath:
path: /home/my-home/repositories/my-project/app/api

本地文件夹/home/my-home/repositories/my-project/app/api存在并且有文件,进入pod,存在/opt/app/api但为空,/home目录正确列在Docker Desktop 的File sharing部分

更新:与microk8s 的配置相同

显然,如果在主机路径的开头添加/host_mnt,它会起作用(请参阅Linux repo的Docker Desktop上的问题(。

也就是说,而不是:

path: /home/my-home/repositories/my-project/app/api

用途:

path: /host_mnt/home/my-home/repositories/my-project/app/api

修改后的完整YAML:

apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 1
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: my-image:latest
resources:
limits:
memory: "0"
cpu: "0"
ports:
- containerPort: 80
volumeMounts:
- name: api-code
mountPath: /opt/app/api
volumes:
- name: api-code
hostPath:
path: /host_mnt/home/my-home/repositories/my-project/app/api

最新更新