I'm trying to understand how to bind mount a directory from a WSL Linux environment into a Docker container. Most guides and posts focus on mounting to the Windows file system, which isn't what I need since development is really slow with that approach. I attempted the following command:
`docker run -it --mount type=bind,src="$(pwd)",dst="/app" node22:latest`
This didn't work because it resolved to an incorrect path (/home/username123/projects/app) that just points to nowhere inside the Linux distro. I also tried:
`docker run -it --mount type=bind,src="\wsl.localhostDebianhomeusername123projectsapp",dst="/app" node22:latest`
However, this command failed with an error about needing an absolute path. I'm confused about how to properly bind mount a directory from my WSL setup. Why isn't there clear documentation on this? Does anyone have a solution? I'm currently using Docker Desktop with WSL2 based on Debian 13.2.
3 Answers
Honestly, if you keep running into issues, maybe consider switching to a Docker container based on Ubuntu or Debian directly instead of working with WSL. Some users prefer sticking to VMs for their setups. But if you need Docker to access certain features like GPU support, WSL might be the way to go.
If you're running the docker command from the WSL terminal, you might want to try this format:
```bash
docker run -it --volume /home/username123/projects/app:/app node22:latest
```
Or navigate to the app directory first:
```bash
cd /home/username123/projects/app
docker run -it --volume ./:/app node22:latest
```
You can only bind mount to the host OS file system in Docker, but WSL has some integration that allows for specific usage. When you run Docker inside WSL, it essentially operates in its own virtual machine, which complicates the path mapping. You can access your WSL files as if they’re a network share, rather than dealing with typical file paths. Just remember, the Windows filesystem and your WSL environment interact in a unique way!
Exactly! It's tricky because Windows views those Linux file paths differently. That's why conventional absolute paths might not work directly.

Good point! WSL has its pros and cons depending on your needs, especially for performance. Just a matter of weighing your options!