Mapping volumes - short command for local repo in W11

Hi all. Beginner to docker here and really pleased with how it’s going. At the moment I’m learning about volumes and specifically mapping host > docker filepaths. One thing I can’t seem to figure is the local repo shortcode to map.

All works good if provide fullpath e.g.
> docker run -v C:\Users\web1928\Documents\www\somefolder:/usr/share/nginx/html/:…

but I was trying to use path command without success
> docker run -v $(pwd):/usr/share/nginx/html/:…

If I just command line $(pwd) it does return the fullpath string, so I figured it should work. Can anyone shed any light on the correct command for this?

Thanks in advance

/Danny

$(pwd) works in linux shells (sh, bash, zsh, …). In Windows, you can try to replace it with $PWD in a powershell terminal or %cd% in a cmd terminal.

Didn’t it return a multiline output like this?

Path
----
C:\Users\username\test

pwd in Powershell is an alias to Get-Location. It works differently. If you don’t use it between quotation marks, it will return an output like above. You can try it:

pwd
echo $(pwd)
echo "$(pwd)"

You can use it this way with docker:

docker run -v "$(pwd):/usr/share/nginx/html/" ...

It was true, until they implemented it in Powershell so Linux users can use Powershell more easily :slight_smile:

1 Like

Good to know.

I also missed out that $PWD returns a multiline ouput as well. echo $(pwd).Path and echo $PWD.Path seem to return just the current working directory.

When trying to use this in the volume mapping, I shouldn’t need to use the echo command, should I?

e.g. > docker run --name mywebsite -d -p 80:80 -v echo $(pwd):/usr/share/nginx/html/ nginx:latest

pwd is executable. $() is not, it executes a command, so you need an executable before it. Obviously, you don’t need $() to run pwd. It is required only to use its output as an argument of an other command. I just used echo for the example, so you could see the result.