Docker Volumes and “print working directory” Command Syntax


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:

Shell

PowerShell Command Window Syntax

You can use the ${PWD} syntax to represent the current working directory:

Onsite Hands-On Training
Interested in onsite training for your team? We offer expert hands-on training classes covering a variety of topics from TypeScript and Angular, to C# and ASP.NET Core, to Docker, Kubernetes, and Azure! Visit https://codewithdan.com for more information.
Shell

Git Bash on Windows Syntax

You can use the /$(pwd) syntax to represent the current working directory:

Shell

Mac/Linux Syntax

You can use $(pwd) syntax to represent the current working directory:

Shell

There 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!

Discuss on Twitter



Join the free Code with Dan Development Newsletter!