Home > Software design >  I can't get the current directory with ${pwd} when running a container in docker
I can't get the current directory with ${pwd} when running a container in docker

Time:10-14

I'm starting to use Docker and I'm reading the docs about bind mounts. I've got an error though that I can't understand about getting the current directory when writing a docker run command.

This is the command that does work indeed:


docker run --rm -d -p 3000:9000 -v "/Users/nick/Documents/commonshood-hash-server:/app" --name dev-server  hash-server-commonshood:0.1

When I use the command:

docker inspect <Container-ID>

It shows me the correct mount. So:

"Mounts": [
            {
                "Type": "bind",
                "Source": "/Users/nick/Documents/commonshood-hash-server",
                "Destination": "/app",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],

Now: I want to use this command here:

docker  \run --rm -d -p 3000:9000 -v ${pwd}:/app hash-server-commonshood:0.1 

But when I inspect the started container I get:

"Mounts": [
            {
                "Type": "volume",
                "Name": "9fda9d77f5434b48d2044a0e1d22cc9331b5b5cc84afea319da70190a394fd6a",
                "Source": "/var/lib/docker/volumes/9fda9d77f5434b48d2044a0e1d22cc9331b5b5cc84afea319da70190a394fd6a/_data",
                "Destination": ":/app",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],

I'm following this page of the official documentation: https://docs.docker.com/storage/bind-mounts/

CodePudding user response:

${pwd} is a variable access, which results in an empty string, since pwd variable is not set. You can either use the ${PWD} variable or the $(pwd) command.

  • Related