Docker
Windows 10
mount volume
current directory
Docker tutorial

Docker: mount the current directory as a volume on Windows 10

Codemia Knowledge Hub ·

To mount the current directory as a volume on Windows 10, pass -v with your shell's current-path variable: ${PWD} in PowerShell, %cd% in Command Prompt, and $(pwd) in Git Bash or WSL. Using the wrong variable for your shell is the most common reason the mount fails silently or shows up as an empty directory in the container.

powershell
# PowerShell (most common on Windows 10)
docker run --rm -v ${PWD}:/app -w /app alpine ls -la
cmd
:: Command Prompt
docker run --rm -v %cd%:/app -w /app alpine ls -la
bash
# Git Bash / WSL
docker run --rm -v "$(pwd)":/app -w /app alpine ls -la

Bind mounts vs named volumes

Docker connects host storage to containers with either bind mounts or named volumes. Mounting the current directory is a bind mount: the host path maps directly into the container's filesystem, and changes on either side are visible on the other immediately.

text
Host:       C:\Users\dev\project\   <-->   Container: /app/
  index.js                                   index.js
  package.json                               package.json

Files created in /app inside the container appear on the host, and host edits appear in the container without a restart.

FeatureBind MountNamed Volume
Host path requiredYes, you specify the exact directoryNo, Docker manages storage location
Data persists after container removalYes, data stays on hostYes, data stays in Docker-managed area
Performance on WindowsSlower (filesystem translation)Faster (native Docker storage)
Use caseDevelopment (live code editing)Production (databases, persistent state)
Syntax-v /host/path:/container/path-v volume_name:/container/path

For editing code on the host and seeing the change instantly in the container, a bind mount is the right choice.

Syntax for each Windows shell

ShellCurrent Directory VariableExample Command
PowerShell${PWD}docker run -v ${PWD}:/app alpine ls
Command Prompt (cmd.exe)%cd%docker run -v %cd%:/app alpine ls
Git Bash (MINGW)$(pwd) with MSYS path conversiondocker run -v "$(pwd)":/app alpine ls
WSL 2 (Ubuntu)$(pwd)docker run -v "$(pwd)":/app alpine ls

Git Bash path conversion

Git Bash converts Unix-style paths to Windows paths automatically, which can break volume mounts. If Docker complains that a path is not valid, add an extra leading slash to turn off conversion:

bash
# Git Bash: disable MSYS path conversion
docker run --rm -v "/$(pwd)":/app -w //app alpine ls -la

Or set MSYS_NO_PATHCONV:

bash
export MSYS_NO_PATHCONV=1
docker run --rm -v "$(pwd)":/app -w /app alpine ls -la

Docker Desktop file sharing

Docker Desktop needs access to the drive that holds your project.

Enabling file sharing

  1. Open Docker Desktop and go to Settings (gear icon).
  2. Go to Resources, then File Sharing.
  3. Make sure the drive with your project (typically C:\) is listed and enabled.
  4. Click Apply and Restart.

If you skip this, Docker mounts an empty directory without any error. The container starts, but the mounted path is empty, which is one of the most confusing failures on Windows.

WSL 2 vs Hyper-V backend

Docker Desktop on Windows 10 runs on either WSL 2 or Hyper-V. With WSL 2 (recommended), file sharing is automatic for paths under \\wsl$\ and most C:\Users\ paths. With the older Hyper-V backend, you must configure shared drives yourself.

To see which backend you use, open Settings, then General, and look at "Use the WSL 2 based engine."

Examples

Node.js with live reload

Mount the project and let a watcher such as nodemon reload on changes:

powershell
1docker run --rm -it `
2  -v ${PWD}:/app `
3  -w /app `
4  -p 3000:3000 `
5  node:20-alpine `
6  sh -c "npm install && npx nodemon index.js"

Edit index.js on Windows and nodemon in the container picks up the change.

Python

powershell
1docker run --rm -it `
2  -v ${PWD}:/app `
3  -w /app `
4  python:3.12-slim `
5  python main.py

Docker Compose

In docker-compose.yml, . means the current directory, resolved relative to the directory containing the compose file:

yaml
1services:
2  app:
3    image: node:20-alpine
4    working_dir: /app
5    volumes:
6      - .:/app
7    ports:
8      - '3000:3000'
9    command: sh -c "npm install && npm start"
powershell
docker compose up

This avoids typing -v by hand and behaves the same in every shell, because Compose resolves the path itself.

Read-only mounts

If the container should read files but never change them, such as configuration files, append :ro:

powershell
docker run --rm -v ${PWD}/config:/app/config:ro alpine cat /app/config/settings.json

The container can read everything in /app/config but cannot create, modify or delete files there.

Debugging an empty or broken mount

powershell
1# 1. Verify Docker can see the path
2docker run --rm -v ${PWD}:/app alpine ls -la /app
3
4# 2. Check Docker Desktop file sharing settings
5docker info | Select-String "Operating System"
6
7# 3. Inspect mount details on a running container
8docker inspect <container_id> --format '{{json .Mounts}}' | ConvertFrom-Json
9
10# 4. Verify the current directory variable expands correctly
11echo ${PWD}     # PowerShell
12echo %cd%       # cmd.exe

If ls /app shows an empty directory, the likely causes are file sharing not enabled for that drive, the path variable not expanding in your shell, or Git Bash rewriting the path.

File permissions

Windows and Linux handle permissions differently, so files created in the container may show unexpected ownership on the host and the reverse. That is usually fine in development. For production containers, set the user explicitly:

powershell
docker run --rm -v ${PWD}:/app -w /app --user 1000:1000 node:20-alpine node index.js

Mistakes that break the mount

Wrong shell variable. ${PWD} works in PowerShell but not Command Prompt, and %cd% works in Command Prompt but not PowerShell. Mixing them up is the top cause of failed mounts.

File sharing disabled. The mount succeeds, the directory is empty, and no error is shown. Check Settings, then Resources, then File Sharing.

Git Bash path mangling. MINGW turns /app into C:\Program Files\Git\app. Use MSYS_NO_PATHCONV=1 or double the slash on the container path.

Paths outside the user directory. By default Docker Desktop shares only paths under C:\Users. Mounting from D:\projects requires adding that path in the file sharing settings.

Slow node_modules. Bind mounts on Windows are slower than native filesystem access because Docker translates between NTFS and the Linux filesystem. Keep node_modules inside the container with a named volume:

yaml
volumes:
  - .:/app
  - /app/node_modules   # anonymous volume, stays inside container

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design