<p>I'm running a Ubuntu container with SQL Server in my local Kubernetes environment with Docker Desktop on a Windows laptop.
Now I'm trying to mount a local folder (<code>C:\data\sql</code>) that contains database files into the pod.
For this, I configured a persistent volume and persistent volume claim in Kubernetes, but it doesn't seem to mount correctly. I don't see errors or anything, but when I go into the container using <code>docker exec -it</code> and inspect the data folder, it's empty. I expect the files from the local folder to appear in the mounted folder 'data', but that's not the case.</p>
<p>Is something wrongly configured in the PV, PVC or pod?</p>
<p>Here are my yaml files:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: dev-customer-db-pv
  labels:
    type: local
    app: customer-db
    chart: customer-db-0.1.0
    release: dev
    heritage: Helm
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /C/data/sql
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: dev-customer-db-pvc
  labels:
    app: customer-db
    chart: customer-db-0.1.0
    release: dev
    heritage: Helm
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: dev-customer-db
  labels:
    ufo: dev-customer-db-config
    app: customer-db
    chart: customer-db-0.1.0
    release: dev
    heritage: Helm
spec:
  selector:
    matchLabels:
      app: customer-db
      release: dev
  replicas: 1
  template:
    metadata:
      labels:
        app: customer-db
        release: dev
    spec:
      volumes:
        - name: dev-customer-db-pv
          persistentVolumeClaim:
            claimName: dev-customer-db-pvc
      containers:
      - name: customer-db
        image: &quot;mcr.microsoft.com/mssql/server:2019-latest&quot;
        imagePullPolicy: IfNotPresent
        volumeMounts:
          - name: dev-customer-db-pv
            mountPath: /data
        envFrom:
          - configMapRef:
              name: dev-customer-db-config
          - secretRef:
              name: dev-customer-db-secrets
</code></pre>
<p>At first, I was trying to define a volume in the pod without PV and PVC, but then I got access denied errors when I tried to read files from the mounted data folder.</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
      volumes:
        - name: dev-customer-db-data
          hostPath:
            path: C/data/sql
      containers:
        ...        
        volumeMounts:
          - name: dev-customer-db-data
            mountPath: data
</code></pre>
<p>I've also tried to Helm install with <code>--set volumePermissions.enabled=true</code> but this didn't solve the access denied errors.</p>

ngruson
<p>Based on this info from <a href="https://github.com/docker/for-win/issues/5325#issuecomment-567481915" rel="noreferrer">GitHub for Docker</a> there is no support hostpath volumes in WSL 2.</p>
<p>Thus, <strong>next workaround can be used</strong>.</p>
<p>We need just to append <code>/run/desktop/mnt/host</code> to the initial path on the host <code>/c/data/sql</code>.  No need for PersistentVolume and PersistentVolumeClaim in this case - just remove them.</p>
<p>I changed <code>spec.volumes</code> for Deployment according to <a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath-configuration-example" rel="noreferrer">information about hostPath configuration on Kubernetes site</a>:</p>
<pre><code>volumes:
- name: dev-customer-db-pv
  hostPath:
    path: /run/desktop/mnt/host/c/data/sql
    type: Directory
</code></pre>
<p>After applying these changes, the files can be found in <code>data</code> folder in the pod, since <code>mountPath: /data</code></p>
