Sharing Source Code. Git Bash. Multiple Issues & Solutions

docker run -d -p 5001:3000 -v $(pwd):/app react-app

Pulled my hair out over this one…

Below I walk through the issues I encountered using Git Bash with solutions… hope it’ll save someone some time.

1st issue: my pwd path had a space in it
Solution: wrap “$(pwd):/app” in quotes

2nd issue:
Error: sh: react-scripts: not found

Reason: it can’t find node_modules dir (cause host gets mirrored but doesn’t have node_modules)

Solution (thanks @jediampm):
https://forum.codewithmosh.com/t/docker-section-5-working-with-containers-lesson-11-error-and-solution/6380

3rd issue: App runs in browser but changes in Host are not applied to dir in container (I believe due to permission issue)

Solution (thank you chat gpt):

docker inspect -f “{{.Mounts}}” <container id>
(this showed “rprivate” at the end, which apparently indicates a permission issue)

docker run -d -p 5000:3000 -v "$(pwd)/src:/app/src:rshared" react-app

4th issue: Changes in Host dir are applied to dir in Container BUT won’t show in browser
Solution: add this line to scripts object inside package.json (then re-build image)

"scripts": {
        "start": "**CHOKIDAR_USEPOLLING=true** react-scripts start", //add this line
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
}

https://stackoverflow.com/a/70017772

5th issue: container runs, but browser indicates permission issue
Solution: delete node_modules dir in Host directory
https://stackoverflow.com/a/70745080

6h later I had the desired mapping btw host and container…

Hope it helps someone.

1 Like

Im facing the 4th issue, I create the volume (bind), the changes in the host are applied in the container But doesnt show in the browser (unless I create another container). I applied the sugested soluction “start”: “CHOKIDAR_USEPOLLING=true react-scripts start” but didnt work. Still this a valid solution?
Im using

  • docker : 24.0.6
  • react: 18.2
  • node: 20.9 and npm version: 10.10