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.

1 Like

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 !
1 Like

To fix

error Couldn't find a package.json file in "/app

cd app
Then run the command again. Because by default I got app/app/ double folders (on Windows)
(Hope it’ll be useful to someone)

I think the tutorial was missing a step. First execute this command:

cd app

Next, execute this command:

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

Note: I ran this on Windows 10 Pro March 2021 all updates.

I ran into the same issues with cygwin on windows 10 pro. I ran it with no issues on my Linux box. I went back to windows and tried from cmd. I got a new docker error complaining about the path having invalid characters. I switched to power shell and the command that gustavo1999 listed works fine. I guess the solution is to use power shell to run the commands on Windows. I did get a warning from windows saying the performance would suffer using a bind mount.

Your solution worked, thanks!

providing absolute path in place of “(pwd)…” thing worked for me as mentioned by other guy. That second Multi container command, I did the Powershell version and it worked as it is.

Did you complete the tutorial?
I completed, and after docker compose, the final app doesn’t persists DB, so should I follow the persist DB Tutorial once again to make it work?

Hi all!

At first you need to be in directory of tutorial project ‘getting-started’ or ‘app’ (whatever you named it), which you downloaded on ‘Step 2: Sample application’ or if your tutorial running from container (like mine) step called ‘Our Application’.
So, go to ‘app’ directory and run in linux (i’m in Ubuntu console running from Windows):
docker run -dp 3000:3000 -w /app -v “$(pwd):/app” node:12-alpine sh -c “yarn install && yarn run dev”

It works for me.

Have a nice day!

Follow this step :
1 - set myvar=%cd%
2 - docker run -dp 3000:3000 -w /app -v %myvar%\app:/app sh -c “yarn install && yarn run dev”

This works for me.

I experienced the same problem. I confused the $(pwd) with the environment variable and typed in $(PWD), whereas the pwd refers to the pwd (print working directory) function.

The tutorial now has separate commands for Linux and (PowerShell in) Windows. I removed the tick marks and made the command one line and that works in PowerShell except with the additional task described below.

I had totally forgotten that when I got to this part.

Well the tutorial does (now) say from the app directory.

I think it would help if the tutorial was improved a bit more and said something like that. Note that it is Part 2: Sample application, not Step 2: Sample application.

I get file permission errors when I run step 2 for Windows of the Getting started: Part 6: use bind mounts tutorial:

yarn install v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
error Could not write file "/app/yarn-error.log": "EACCES: permission denied, open '/app/yarn-error.log'"
error An unexpected error occurred: "EACCES: permission denied, mkdir '/app/node_modules'".

I am running step 2 from /getting-started/app and am running PowerShell as an admin. I changed PowerShell execution policies to unrestricted.