getting-started: Using Bind Mounts: error Couldn't find a package.json file in "/app"
I was having an issue completing the steps in Starting a Dev-Mode Container.
- Run the following command (if you are using PowerShell then use this command):
docker run -dp 3000:3000 ` -w /app -v “$(pwd):/app” ` node:12-alpine ` sh -c “yarn install && yarn run dev”
An image ID would be output in the shell, but examining the container using Docker Desktop revealed the container had exited with the following terminal output:
yarn install v1.22.4 [1/4] Resolving packages… success Already up-to-date. Done in 0.05s. 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.
I had to update the command in step 2 to the following:
docker run -dp 3000:3000 ` -w /app -v “$(pwd):/app” ` node:12-alpine ` sh -c “cd app && yarn install && yarn run dev”
Is this an appropriate work around?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 55
- Comments: 34
Commits related to this issue
- Fix #76 If the user runs that command "from the source code folder", i.e. `getting-started`, docker will bind-mount `getting-started` to the container's `/app`, which leads to error `error Couldn't f... — committed to yuuyins/getting-started by yuuyins 2 years ago
- Fix #76 If the user runs that command "from the source code folder", i.e. getting-started, docker will bind-mount getting-started to the container's /app, which leads to error error Couldn't find a p... — committed to yuuyins/getting-started by yuuyins 2 years ago
- Fix #76 If the user runs that command "from the source code folder", i.e. `getting-started`, docker will bind-mount getting-started to the container's `/app`, which leads to error `error Couldn't fin... — committed to yuuyins/getting-started by yuuyins 2 years ago
- Merge pull request #243 from yuuyins/issue-76-2 Fix #76 — committed to docker/getting-started by StefanScherer 2 years ago
The tutorial mentions only once early on which directory you should run commands from when starting the tutorial, so it’s easy to miss.
We need to be inside the
app
directory.So after unzipping the getting-started tutorial we have something like d:\getting-started\app If running the
docker run
command from d:\getting-started\ you’ll get the above error.So
cd
into d:\getting-started\app and try the command again.Hi @MSoup , I am also new to docker today I faced same issue with windows 10 only,
my working directory is
E:\DockerPractice\getting-started\app
so what I did is
docker run -dp 3000:3000 -w //app -v "//e/DockerPractice/getting-started/app:/app" node:12-alpine sh -c "yarn install && yarn run dev"
this command works fine for me
had the same issue, this fixed it
I guess you’re using Windows, which is not quite oriented with variable aka $pwd for example, so either:
Adding the
cd app &&
tosh -c "cd app && yarn install && yarn run dev"
fixed the problem for me. Thank you!Hi, I also ran into this issue in vs code using Windows 10 in bash command line.
If you haven’t solved this or if someone else is in a similar situation and has not come to a resolution. I solved this little issue by using the powershell version of the suggested command in powershell.
@sujirou The docker command you’ve copy/pasted won’t persist anything. If you continue further into the tutorial it shows how persistence is done using named volumes which live separate from containers and won’t be deleted if you delete or stop/restart a container.
The problem originates with the tutorial itself. In step 1 it says “At the root of the app project, create a file named docker-compose.yml”
This might lead someone to put the yaml file in the root of the project, in which case we get the “cannot fine package.json” error. It won’t matter whether you run docker compose from within /app or not. If you do put the yaml file in the project root then you must put “cd app” inside the command.
If you put the yaml file in /app folder itself, then you only need to run
docker compose up -d
and it should work as expected.If you are using WSL with Ubuntu on Windows and using an Ubuntu terminal (not Powershell) , I finally was able to get it to work by not using the $(pwd) part and using the actual path in Windows. Using the ‘/mnt/c/temp/Downloads/app/app:/app’ did not work, but specifying the Windows equivalent path ‘C://temp//Downloads//app//app:/app’ actually works. Not sure why but WSL won’t use the correct path if you use the ‘/mnt/c/’ or the pwd.
Not working:
docker run -dp 3000:3000 -w /app -v "/mnt/c/temp/Downloads/app/app:/app" node:12-alpine sh -c "yarn install && yarn run dev"
Working:
docker run -dp 3000:3000 -w /app -v "C://temp//Downloads//app//app:/app" node:12-alpine sh -c "yarn install && yarn run dev"
Note, I was able to get the PowerShell version command to work fine that the tutorial provided. However, I want to be exclusively in a Ubuntu shell/terminal, not Powershell/Command, so this was important to figure out if it was indeed compatible.
Hope this saves someone else some frustrations/time.
I encountered essentially the same problem as reported by @bseth15 twice: (a) in Part 6, “Using bind mounts,” and again Part 7, “Multi container apps.” Thank you for the helpful suggestions. I would recommend changing the language in the tutorial accordingly. In Part 6, in the “Start a dev-mode container” section, I’d recommend changing “Run the following command.” to read “Run the following command from the app/ directory.” Similarly, in Part 7, in the “Run your app with MySQL” section, Id recommend changing “We’ll specify each of the environment variables above, as well as connect the container to our app network.” to “We’ll specify each of the environment variables above, as well as connect the container to our app network. Run the following from the app/ directory.”