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.