In docker-compose, //bin/sh:1:node-dev:not found と

Asked 2 years ago, Updated 2 years ago, 90 views

What do you expect

docker-compose-f docker-compose.yml up-d --build The frontend container starts after execution.

Problems

After running docker-compose-f docker-compose.yml up-d --build, check docker ps-a to see the frontend container as STATUS itExited(1) 」.
docker-compose logs results in the following:

 yarn run v1.22.4
$ react-scripts start
/bin/sh:1:react-scripts:not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

After removing the "CMD yarn start" in the Dockerfile from the above results and accessing the terminal with docker run, we were able to confirm that "node_modules" exists and that "react-scripts" exists.

#ls-l node_modules | grepreact-scripts
drwxr-xr-x9 root root 4096 Aug 704:01 react-scripts

In addition, yarn start can be started in this state.

environment

Windows 11 Home Memory: 16GB Docker Desktop

 FROM node:12.16.3

WORKDIR/app

COPY frontend/package.json.

RUN yarn install

COPY.

EXPOSE 3000

CMD yarn start
version:"3"

services:
 frontend:
  env_file:./.env
  build:
   context:.
   dockerfile —Dockerfile.frontend
  command: "yarn start"
  ports:
   - "3000:3000"
  volumes:
   - ./frontend:/app
  tty —true
 -----------------------------------------
"scripts": {
    "lint": "eslint./src",
    "lint-fix": "eslint--fix./src",
    "start": "react-scripts start",
    "build": "react-scripts build",
    "eject": "react-scripts eject"
}
-----------------------------------------

docker docker-compose yarn

2022-09-30 13:54

1 Answers

The container image generated by docker build appears to contain node_modiles, but it seems to be overwritten and not present because it binds the local file ./frontend.

Use docker-composer run (or exec) instead of docker run to ensure that you are aligned with the failed situation.

The solution is to run docker-compose run --rmyarn and try again with yarn install bound mounted.(The node_modules are written outside the container.)

By the way, the error content is slightly different between the title and the text, but is it a transcription error?


2022-09-30 13:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.