Reputation: 2409
I have a react app made with create-react-app with a PHP backend that I was wanting to containerize and thought would be a good first project to get more familiar with Docker. Initially, I had the docker container running on Windows, but when editing the source could, builds were painfully slow. After some research, it was suggested to move the repo directly into Windows Subsystem for Linux (WSL) to speed up file transfers.
After copying the files to WSL and calling docker compose up --build
, I started getting a react-scripts: Permission denied
error. Assuming this was an issue from copying the files over, I deleted the node_modules
folder and tried docker compose up --build
again. Now, I'm getting react-scripts: not found
.
After checking, the node_modules
in the container is populated and the react-scripts
is present, but ./app/node_modules
is empty.
Since, I have the node_modules
folder setup as a volume, shouldn't they be synced? I've tried everything I can find to get it to work, including docker system prune -a --volumes
and rebuilding everything from scratch and the ./app/node_modules
is still empty.
How can I get the react-scripts
command to run without the permissions issue? Shouldn't just work the same as it did in Windows?
Note: npm start
is just an alias for react-scripts start
.
# ./docker-compose.yaml
version: "3.8"
services:
app:
build:
context: ./app
dockerfile: Dockerfile
ports:
- 3000:3000
volumes:
- ./app:/app
- ./app/node_modules:/app/node_modules
environment:
- WATCHPACK_POLLING=true
- BROWSER=none
# ./app/Dockerfile
FROM node:18 AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
# ./app/.dockerignore
node_modules
npm-debug.log
Dockerfile
.dockerignore
.git
.gitignore
.vscode
[+] Building 58.7s (11/11) FINISHED docker:default
=> [app internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 336B 0.0s
=> [app internal] load metadata for docker.io/library/node:18 1.1s
=> [app internal] load .dockerignore 0.0s
=> => transferring context: 121B 0.0s
=> [app 1/5] FROM docker.io/library/node:18@sha256:f12d34408955b2081f82078e8f96c3299ca0f38d11e76086cb9b9b1b669977e4 24.4s
=> => resolve docker.io/library/node:18@sha256:f12d34408955b2081f82078e8f96c3299ca0f38d11e76086cb9b9b1b669977e4 0.0s
=> => sha256:a492eee5e55976c7d3feecce4c564aaf6f14fb07fdc5019d06f4154eddc93fde 48.48MB / 48.48MB 3.8s
=> => sha256:35af2a7690f2b43e7237d1fae8e3f2350dfb25f3249e9cf65121866f9c56c772 64.39MB / 64.39MB 9.5s
=> => sha256:f12d34408955b2081f82078e8f96c3299ca0f38d11e76086cb9b9b1b669977e4 6.41kB / 6.41kB 0.0s
=> => sha256:d4cd021b33732523d311a6c9eac765b0229e31962adedc7990333ff865a5b25d 2.49kB / 2.49kB 0.0s
=> => sha256:9cc56e2c51419614a5027c82bc07fad1f9bc07db014dd7ec184e1ff8c1f4393b 6.39kB / 6.39kB 0.0s
=> => sha256:32b550be6cb62359a0f3a96bc0dc289f8b45d097eaad275887f163c6780b4108 24.06MB / 24.06MB 3.9s
=> => extracting sha256:a492eee5e55976c7d3feecce4c564aaf6f14fb07fdc5019d06f4154eddc93fde 3.3s
=> => sha256:7576b00d9bb10cc967bb5bdeeb3d5fa078ac8800e112aa03ed15ec199662d4f7 211.33MB / 211.33MB 16.6s
=> => sha256:d55bd4ee018bb8787aaa9ea963210d6762a3c3243daca340f099c12dc76dc8a0 3.32kB / 3.32kB 4.1s
=> => sha256:699c77750bbfa3355160caafaffc0809bf2fc503cb6b3432975faba7101eaf8f 45.72MB / 45.72MB 8.8s
=> => extracting sha256:32b550be6cb62359a0f3a96bc0dc289f8b45d097eaad275887f163c6780b4108 1.1s
=> => sha256:a90d998fbd35e749dd38959f8e6632895f944df7662d041c5cd44c7e61697bbe 1.25MB / 1.25MB 9.1s
=> => sha256:0d7872d72f6bb464d751d0a19af2d095b0dde109eb23fbabae9470ea987a912e 447B / 447B 9.5s
=> => extracting sha256:35af2a7690f2b43e7237d1fae8e3f2350dfb25f3249e9cf65121866f9c56c772 3.1s
=> => extracting sha256:7576b00d9bb10cc967bb5bdeeb3d5fa078ac8800e112aa03ed15ec199662d4f7 5.4s
=> => extracting sha256:d55bd4ee018bb8787aaa9ea963210d6762a3c3243daca340f099c12dc76dc8a0 0.0s
=> => extracting sha256:699c77750bbfa3355160caafaffc0809bf2fc503cb6b3432975faba7101eaf8f 1.9s
=> => extracting sha256:a90d998fbd35e749dd38959f8e6632895f944df7662d041c5cd44c7e61697bbe 0.0s
=> => extracting sha256:0d7872d72f6bb464d751d0a19af2d095b0dde109eb23fbabae9470ea987a912e 0.0s
=> [app internal] load build context 0.1s
=> => transferring context: 6.21MB 0.1s
=> [app 2/5] WORKDIR /app 3.2s
=> [app 3/5] COPY package.json package-lock.json ./ 0.0s
=> [app 4/5] RUN npm install 26.0s
=> [app 5/5] COPY . . 0.1s
=> [app] exporting to image 3.6s
=> => exporting layers 3.6s
=> => writing image sha256:f2dd256518778bd48fc348c1e239ebfcccd2305baeeb9798fe026ebe374fd1ff 0.0s
=> => naming to docker.io/library/ship-explorer-app 0.0s
=> [app] resolving provenance for metadata file 0.0s
[+] Running 3/3
✔ app Built 0.0s
✔ Network ship-explorer_app-network Created 0.2s
✔ Container ship-explorer-app-1 Created 0.1s
Attaching to app-1
app-1 |
app-1 | > [email protected] start
app-1 | > react-scripts start
app-1 |
app-1 | sh: 1: react-scripts: not found
app-1 exited with code 127
Upvotes: 0
Views: 48