<p>I am unable to properly mount volumes using HostPath within Kubernetes running in Docker and WSL 2. This seems to be a WSL 2 issue when mounting volumes in Kubernetes running in Docker.  Anyone know how to fix this?</p>
<p>Here are the steps:</p>
<p>Deploy debug build to Kubernetes for my app.
Attach Visual Studio Code using the Kubernetes extension
Navigate to the project folder for my application that was attached using the volume mount &lt;= Problem Right Here</p>
<p>When you go and look at the volume mount nothing is there.</p>
<pre><code>C:\Windows\System32&gt;wsl -l -v

NAME STATE VERSION
Ubuntu Running 2
docker-desktop-data Running 2
docker-desktop Running 2
Docker Desktop v2.3.0.3
Kubernetes v1.16.5
Visual Studio Code v1.46.1
</code></pre>
<pre><code>====================================================================
Dockerfile
====================================================================
#
# Base image for deploying and running based on Ubuntu
#
# Support ASP.NET and does not include .NET SDK or NodeJs
# 
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
#
# Base image for building .NET based on Ubuntu
#
# 1. Uses .NET SDK image as the starting point 
# 2. Restore NuGet packages
# 3. Build the ASP.NET Core application
#
# Destination is /app/build which is copied to /app later on
#
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS build
WORKDIR /src
COPY [&quot;myapp.csproj&quot;, &quot;./&quot;]
RUN dotnet restore &quot;./myapp.csproj&quot;
COPY . .
WORKDIR &quot;/src/.&quot;
RUN dotnet build &quot;myapp.csproj&quot; -c Release -o /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS debug
RUN curl --silent --location https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install --yes nodejs
ENTRYPOINT [ &quot;sleep&quot;, &quot;infinity&quot; ]

#
# Base image for building React based on Node/Ubuntu
#
# Destination is /app/ClientApp/build which is copied to /clientapp later
#
# NOTE: npm run build puts the output in the build directory
#
FROM node:12.18-buster-slim AS clientbuild
WORKDIR /src
COPY ./ClientApp /app/ClientApp
WORKDIR &quot;/app/ClientApp&quot;
RUN npm install
RUN npm run build
#
# Copy clientbuild:/app/ClientApp to /app/ClientApp
#
# Copy build:/app to /app
#
FROM base as final
WORKDIR /app/ClientApp
COPY --from=clientbuild /app/ClientApp .
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT [&quot;dotnet&quot;, &quot;myapp.dll&quot;]

====================================================================
Kubernetes Manifest
====================================================================
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  selector:
    matchLabels:
      app: myapp
  replicas: 1
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: localhost:6000/myapp
        ports:
        - containerPort: 5001
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /local
          name: local
        resources: {}        
      volumes:
      - name: local
        hostPath:
          path: /C/dev/myapp
          type: DirectoryOrCreate
      hostname: myapp
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  type: LoadBalancer
  ports:
  - name: http
    protocol: TCP
    port: 5001
    targetPort: 5001
  selector:
    app: myapp
</code></pre>

<p>According to the following thread, hostPath volumes are not officially supported for wsl2, yet. They do suggest a workaround, though I had trouble getting it to work. I have found that prepending <code>/run/desktop/mnt/host/c</code> seems to work for me.</p>
<pre><code>// C:\someDir\volumeDir
hostPath:
  path: /run/desktop/mnt/host/c/someDir/volumeDir
  type: DirectoryOrCreate
</code></pre>
<p>Thread Source: <a href="https://github.com/docker/for-win/issues/5325" rel="noreferrer">https://github.com/docker/for-win/issues/5325</a><br />
Suggested workaround from thread: <a href="https://github.com/docker/for-win/issues/5325#issuecomment-567594291" rel="noreferrer">https://github.com/docker/for-win/issues/5325#issuecomment-567594291</a></p>
