[Docker] section 5 (Working with Containers) lesson 11- error and solution

Hi,

by executing the command

docker run -d -p 80:3000 -v $(pwd):/app  --name web  wa

the container stop , so went see the logs and i had the follow error:

> react-app@0.1.0 start /app
> react-scripts start

sh: react-scripts: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! react-app@0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the react-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

so after some trials / tests, i came to this conclusion:

  • you are mirror / bind / watch same files, so with this command you lost the node_modules since all files of main host are replicated to the container and the host do not have the node_modules folder.

  • so in this case, you should not bind /mirror /watch the root folder but another folder that is inside of app folder, that you will change the files.

Solution:

  • in Case of a react app, most files that you will change are the files that are inside of src folder

instead of :

docker run -d -p 80:3000 -v $(pwd):/app  --name web  wa

replace with:

docker run -d -p 80:3000 -v $(pwd)/src:/app/src  --name web  wa

if you want to add files to public folder you can:

  • execute the command that copy from host to container ( watch the lesson 10 from section 5) or

  • add another volume beside to a src folder like

    -v $(pwd)/public:/app/public

joining to watch src and public folder do:

docker run -d -p 80:3000 -v $(pwd)/src:/app/src  -v $(pwd)/public:/app/public --name web  wa

i hope this post will help anyone.

2 Likes

I find a better and short way with anonymous volume, which are temp volume and we say to docker engine while container is running do not remove this folder when bind volume from the host by adding the following command:

# this means keep this folder on running container
-v "/app/node_modules"

in the terminal:

docker run -d -p 80:3000 -v /app/node_modules -v $(pwd):/app --name web wa

or you can add anonymous volumes to dockerfile like this, before CMD

VOLUME [ "/app/node_modules" ]

then in terminal :

docker run -d -p 80:3000 -v $(pwd):/app --name web wa

:wink:

I run into a problem that the app doesn’t update after I modify the files. I’ve copied your code and it doesn’t solve on my problem. Do you know how to solve this? Thanks
[UPDATE]: I ran docker exec -it <ID> sh and look into the index.html. I noticed that the file was updated but the app’s title in the browser never update even I refresh the page manually.