How to mount a directory in windows on a container with Kubernetes on Docker for Windows?

Viewed 1382

I am using Docker for Windows 2.3.0.4 (stable) backed by WSL2 on Windows 10 version 2004 and with Kubernetes support enabled.

I am trying to create the following pod:

apiVersion: v1
kind: Pod
metadata:
  name: api0
spec:
  volumes:
    - name: "mongo-data"
      hostPath:
        path: "/c/wr/volumes/mongo/data"
  containers:
  - name: db
    image: mongo:3.6.19-xenial
    volumeMounts:
      - mountPath: "/data/db"
        name: "mongo-data"
    resources:
      limits:
        memory: "512Mi"
        cpu: "1"
    ports:
      - containerPort: 27017

I have an issue with the mongo-data volume; when the pod is created via kubectl apply -f api0.yml the pod runs properly and the MongoDB collections are persisted after deleting and re-applying the pod.

But the C:\wr\volumes\mongo\data path that is mounted to the mongo db container does not contain the data files and is always empty

As I mentioned before, the state is persisted somewhere but not in the specified path.

What am I missing?

I tried specifying the path with the following formats:

  • /c/wr/volumes/mongo/data
  • //c/wr/volumes/mongo/data
  • //////c/wr/volumes/mongo/data
  • /mnt/c/wr/volumes/mongo/data

And I even tried referencing the /opt/data path in the wsl filesystem but the data files are never there.

0 Answers
Related