Search code examples
dockerdocker-volume

Docker - Docker is Complaining When Using $PWD: In Windows 10 Pro


I am learning docker right now and just trying to follow along with their tutorial. I am already in the topic of Using Bind Mounts and I encountered an issue that I can't seem to find a solution. I tried executing the following command just like what's in the tutorial,

docker run -dp 3000:3000 \ -w /app -v $PWD:/app \ node:12-alpine \ sh -c "yarn install && yarn run dev"

..but it keeps on throwing the following error message,

At line:1 char:39 + docker run -dp 3000:3000 \ -w /app -v $PWD:/app \ node:12-alpine \ sh ... + ~~~~~ Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : InvalidVariableReferenceWithDrive

I already tried using the following solutions,

docker run -dp 3000:3000 \ -w /app -v ${PWD}:/app \ node:12-alpine \ sh -c "yarn install && run dev"
docker run -dp 3000:3000 \ -w /app -v "${PWD}:/app" \ node:12-alpine \ sh -c "yarn install && run dev"
docker run -dp 3000:3000 \ -w /app -v "${PWD}":/app \ node:12-alpine \ sh -c "yarn install && run dev"
docker run -dp 3000:3000 \ -w /app -v ${pwd}:/app \ node:12-alpine \ sh -c "yarn install && run dev"
docker run -dp 3000:3000 \ -w /app -v "${pwd}:/app" \ node:12-alpine \ sh -c "yarn install && run dev"
docker run -dp 3000:3000 \ -w /app -v "${pwd}":/app \ node:12-alpine \ sh -c "yarn install && run dev"

...but to no avail and I am just seeing this error,

C:\Program Files\Docker\Docker\resources\bin\docker.exe: invalid reference format. See 'C:\Program Files\Docker\Docker\resources\bin\docker.exe run --help'.

I'll appreciate it if someone could help and guide me resolve this. :)


Solution

  • Please try the below command.

    $ docker run -dp 3000:3000 -w /app -v ${PWD}:/app  node:12-alpine  sh -c "yarn install && run dev"
    

    You have to remove the \ as you have written the command in one line.

    \ is most commonly used in situations like these (i.e. to make it easier to read a long command):

    docker run -p 3000:3000 \
    -w /app -v $PWD:/app \
    node:12-alpine \
    sh -c "yarn install && yarn run dev"