 I often use Docker to run an application in a container as I’m writing and testing code. That involves creating a volume that points the container to a path on my machine. The challenge with setting up volumes is that the “print working directory” command that is often used to easily identify the location of your source code on the host machine is different depending on what command terminal you’re using (especially on Windows).
I often use Docker to run an application in a container as I’m writing and testing code. That involves creating a volume that points the container to a path on my machine. The challenge with setting up volumes is that the “print working directory” command that is often used to easily identify the location of your source code on the host machine is different depending on what command terminal you’re using (especially on Windows).
Here’s a quick summary that shows the syntax for “print working directory” in different command terminals when using volumes (if you’re new to volumes you can read more about them here). An nginx container path is shown to provide a simple example of a volume pointing to the current working directory on the host machine.
Windows Command Window Syntax
You can use the %cd% syntax to represent the current working directory:
 -v %cd%:/usr/share/nginx/htmlPowerShell Command Window Syntax
You can use the ${PWD} syntax to represent the current working directory:
 -v ${PWD}:/usr/share/nginx/htmlWindows Subsystem for Linux (WSL) with a Windows Directory Syntax
If you’re referencing a Windows directory from WSL2 you can use the following syntax.
NOTE: It’s recommended you reference a directory that is within WSL rather than within Windows for performance reasons.
-v /mnt/c/username/some-windows-directory:/usr/share/nginx/htmlGit Bash on Windows Syntax
You can use the /$(pwd) syntax to represent the current working directory:
-v /$(pwd):/usr/share/nginx/htmlMac/Linux Syntax
You can use $(pwd) syntax to represent the current working directory:
-v $(pwd):/usr/share/nginx/htmlThere are additional variations of the “print working directory” syntax shown above. If you prefer to use a different one please leave a comment with the information – share the knowledge!
 
											




