Mount current directory as a volume in Docker on Windows 10
In Windows Command Line (cmd
), you can mount the current directory like so:
docker run --rm -it -v %cd%:/usr/src/project gcc:4.9
In PowerShell, you use ${PWD}
, which gives you the current directory:
docker run --rm -it -v ${PWD}:/usr/src/project gcc:4.9
On Linux:
docker run --rm -it -v $(pwd):/usr/src/project gcc:4.9
Cross Platform
The following options will work on both PowerShell and on Linux (at least Ubuntu):
docker run --rm -it -v ${PWD}:/usr/src/project gcc:4.9docker run --rm -it -v $(pwd):/usr/src/project gcc:4.9
- Open Settings on Docker Desktop (Docker for Windows).
- Select Shared Drives.
- Select the drive that you want to use inside your containers (e.g., C).
The command below should now work on PowerShell (command prompt does not support
${PWD}
):docker run --rm -v ${PWD}:/data alpine ls /data
IMPORTANT: if/when you change your Windows domain password, the mount will stop working silently, that is, -v
will work but the container will not see your host folders and files. Solution: go back to Settings, uncheck the shared drives, Apply, check them again, Apply, and enter the new password when prompted.