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.