Docker Community Forums

Share and learn in the Docker community.

Bind mounts - docker run command in Getting Started tutorial not working

I am working on Win - 10 host and linux container. I have successfully followed tutorial docker/getting-started on localhost but when I came to subject - persisting data using Bind Mounts I got stuck.

There’s a command which is mentioned in the tutorial as -

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

When I try to run this command I am getting error as invalid reference format in cmd prompt. When I run in Win Powershell I get the error as below -

-w : The term ‘-w’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:2 char:5

  • -w /app -v $(PWD):/app \
    
  • ~~
    
    • CategoryInfo : ObjectNotFound: (-w:String) , CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

node:12-alpine : The term ‘node:12-alpine’ is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:3 char:5

  • node:12-alpine \
    
  • ~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (node:12-alpine:String) , CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

sh : The term ‘sh’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:4 char:5

  • sh -c "yarn install && yarn run dev"
    
  • ~~
    
    • CategoryInfo : ObjectNotFound: (sh:String) , CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

Can anyone please help me over here? I am near to finish the tutorial and I am getting this errors.

Not only this, I tried to skip and proceed further to Multi-Container where there is a command -

docker run -d
–network todo-app --network-alias mysql
-v todo-mysql-data:/var/lib/mysql
-e MYSQL_ROOT_PASSWORD=secret
-e MYSQL_DATABASE=todos
mysql:5.7

which also throws the error as invalid reference format.

Thanks.

As a rule-of-thumb: don’t use Windows for docker.

And yes, your command line is “malformed” and doesn’t make sense. (sorry)
Do you have a link to the tutorial or can you tell me what you want to achive with these commands ?

Also check: https://docs.docker.com/storage/

Hi,

I am using docker/getting-started tutorial from the docker website. And I am trying to run this below command.

Ok … this example is highly misleading IMHO when it comes to bind mounts …
But first things first. The example was not written for a windows environment. Win interprets a “\” (very) different from Linux. And that’s the reason it doesn’t work.
I don’t have a Win Box with docker, so I can’t really tell, but try to double the Backslash -> \
Or write all in just one line:

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

However, this will successfully create a container, but the container itself fails to start:

docker logs 70edc83aef35

yarn install v1.22.4
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 0.04s.
yarn run v1.22.4
error Couldn't find a package.json file in "/app"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

… and I have no idea how to fix this …

Anyway it should be a lesson on “bind mounts”, so you might consider skipping this exercise and focus on this doc instead -> https://docs.docker.com/storage/

Hi,

Thanks for your response. Now I had moved on with volumes instead of Bind Mounts.

Thanks - I also had issues with that exercise and had started writing it out in long form - the .json file was in previous exercise - however, I’m getting errors on running the command for invalid characters, which I cant see.

D:\jimda\Downloads\app\app>docker run -dp 3000:3000 -w /app -v ${PWD}:/app node:12-alpine sh -c “yarn install && yarn run dev”

docker: Error response from daemon: create {PWD}: "{PWD}" includes invalid characters for a local volume name, only “[a-zA-Z0-9][a-zA-Z0-9_.-]” are allowed. If you intended to pass a host directory, use absolute path.
See ‘docker run --help’

Path looks ok, but wondering if this is a symbolic link as Windows moved it from C drive?

I’m wondering if Windows can resolve “${PWD}” as this is a Linux/Unix shell variable that holds your current directory your’re in. The same as you’d type: “pwd” -> print working directory.

So either switch to Linux (highly recommended :wink: ) or try absolute paths instead.

Its odd - as I thought it was passing into a container (linux) on creation - but was the getting started shipped with the Windows version.

Its 18 years since I did Linux, so was trying to ease myself in with Docker on Windows first… Got the ubuntu image installed ready…

I have found a way to make it work on my Windows computer. I’m using following command:
docker run -dp 3000:3000 -w /app -v "C:\Users\thoma\Documents\Code\DockerTest\app":/app node:12-alpine sh -c "yarn install && yarn run dev"

So fixes to make it work on windows:

  • Remove all \ to make it a one row command
  • Replace ${PWD} by an absolute path using double quote around "
  • Don’t forget the :/app after the path to name it !

hen creating bind mounts, you need two things… 1) the source of the mount and 2) the target of the mount. The source is typically a directory or file on the host and the target is where in the container that source should be made available.

The $PWD piece is basically saying “the current directory.” For example, if you run (in your cli) echo $PWD, you should get the full path to the current directory.

The specific error you’re getting is typically seen when someone types in a docker run but is missing one of the flags. For example, if I ran docker run 80:80 nginx (missing the -p in front of 80:80), the run command is going to think the 80:80 is the image name, since there is no flag in front of it. That obviously won’t resolve and will cause an error. So, the first thing to look at is to make sure you’re typing the command exactly right.

If you’ve verified that and you’re still having trouble, I’ll need a little more info. If you could take a screenshot of the command and the error you’re seeing and attach it here, that would be awesome. Secondly, are you running Docker Desktop on Mac or Windows?