質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Yarn

Yarnは、Facebook/Exponent/Google/Tildeが開発したJavaScriptのパッケージマネージャ。npmよりもインストールが速く、厳密にモジュールのバージョンを固定できるなど、npmの問題を解決。npmと互換性があり、同じpackage.jsonを使用できます。

PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

解決済

2回答

7519閲覧

docker-compose,Reactにおける/bin/sh: 1: react-scripts: not foundの解決方法について

BoKuToTuZenU

総合スコア51

docker-compose

docker-composeとは、複数のコンテナで構成されるサービスを提供する手順を自動的し管理を簡単にするツール。composeファイルを使用しコマンド1回で設定した全サービスを作成・起動することが可能です。

Yarn

Yarnは、Facebook/Exponent/Google/Tildeが開発したJavaScriptのパッケージマネージャ。npmよりもインストールが速く、厳密にモジュールのバージョンを固定できるなど、npmの問題を解決。npmと互換性があり、同じpackage.jsonを使用できます。

PostgreSQL

PostgreSQLはオープンソースのオブジェクトリレーショナルデータベース管理システムです。 Oracle Databaseで使われるPL/SQLを参考に実装されたビルトイン言語で、Windows、 Mac、Linux、UNIX、MSなどいくつものプラットフォームに対応しています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2021/02/04 07:30

編集2021/02/04 08:54

問題

docker-composeをもちいてdjango,postgresql,reactをもちいたwebかいはつをおこなっております。
docker内で、reactをbuildしたさいになぜか、pakage.jsonにあるものをinstallしてくれません。
そのため、react-scriptsがないとerrorでおこられます。
がいとうするファイルを共有します。

該当するコード

docker-compose.yml

version: '3' services: db: image: postgres ports: - "5432:5432" environment: POSTGRES_HOST_AUTH_METHOD: 'trust' django: build: ./backend volumes: - ./backend:/backend ports: - "8000:8000" depends_on: - db command: "bash -c 'python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000'" tty: true frontend: build: ./frontend entrypoint: "bash -c 'npm install && yarn start'" volumes: - ./frontend:/frontend ports: - "3000:3000" depends_on: - django volumes: node-modules:

frontのDockerfile

FROM node WORKDIR /frontend COPY package.json /frontend RUN yarn install COPY . /frontend EXPOSE 3000 CMD ["yarn", "run", "start"]

エラー

db_1 | db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization db_1 | db_1 | 2021-02-04 07:24:11.717 UTC [1] LOG: starting PostgreSQL 13.1 (Debian 13.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit db_1 | 2021-02-04 07:24:11.717 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 db_1 | 2021-02-04 07:24:11.717 UTC [1] LOG: listening on IPv6 address "::", port 5432 db_1 | 2021-02-04 07:24:11.736 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" db_1 | 2021-02-04 07:24:11.745 UTC [29] LOG: database system was interrupted; last known up at 2021-02-04 07:21:58 UTC db_1 | 2021-02-04 07:24:11.831 UTC [29] LOG: database system was not properly shut down; automatic recovery in progress db_1 | 2021-02-04 07:24:11.832 UTC [29] LOG: redo starts at 0/163C2B0 db_1 | 2021-02-04 07:24:11.832 UTC [29] LOG: invalid record length at 0/163C2E8: wanted 24, got 0 db_1 | 2021-02-04 07:24:11.832 UTC [29] LOG: redo done at 0/163C2B0 db_1 | 2021-02-04 07:24:11.840 UTC [1] LOG: database system is ready to accept connections django_1 | No changes detected django_1 | Operations to perform: django_1 | Apply all migrations: admin, auth, contenttypes, sessions, todo django_1 | Running migrations: django_1 | No migrations to apply. django_1 | Performing system checks... django_1 | django_1 | System check identified no issues (0 silenced). django_1 | February 04, 2021 - 07:24:13 django_1 | Django version 3.1.6, using settings 'backend.settings' django_1 | Starting development server at http://0.0.0.0:8000/ django_1 | Quit the server with CONTROL-C. frontend_1 | frontend_1 | changed 10 packages, and audited 1835 packages in 2s frontend_1 | frontend_1 | found 0 vulnerabilities frontend_1 | npm notice frontend_1 | npm notice New patch version of npm available! 7.5.1 -> 7.5.2 frontend_1 | npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.5.2> frontend_1 | npm notice Run `npm install -g npm@7.5.2` to update! frontend_1 | npm notice frontend_1 | yarn run v1.22.5 frontend_1 | $ react-scripts start frontend_1 | /bin/sh: 1: react-scripts: not found frontend_1 | error Command failed with exit code 127. frontend_1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. todo_test_frontend_1 exited with code 127

ためしたこと、

Dockerfileにたいして、RUN npm installRUN yarn installに変更。

npm notice npm notice New patch version of npm available! 7.5.1 -> 7.5.2 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.5.2> npm notice Run `npm install -g npm@7.5.2` to update! npm notice npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! Found: react@17.0.1 npm ERR! node_modules/react npm ERR! react@"^17.0.1" from the root project npm ERR! peer react@"*" from @testing-library/react@11.2.5 npm ERR! node_modules/@testing-library/react npm ERR! @testing-library/react@"^11.1.0" from the root project npm ERR! 3 more (react-dom, react-scripts, reactstrap) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer react@"0.14.x || ^15.0.0 || ^16.0.0" from react-popper@1.3.7 npm ERR! node_modules/reactstrap/node_modules/react-popper npm ERR! react-popper@"^1.3.6" from reactstrap@8.9.0 npm ERR! node_modules/reactstrap npm ERR! reactstrap@"^8.9.0" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /root/.npm/eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2021-02-04T08_40_33_006Z-debug.log

node_moudelsをマウントして、package.jsonのreact_scriptsのpathを変更した

frontend_1 | frontend_1 | removed 317 packages, and audited 1835 packages in 3s frontend_1 | frontend_1 | found 0 vulnerabilities frontend_1 | npm notice frontend_1 | npm notice New patch version of npm available! 7.5.1 -> 7.5.2 frontend_1 | npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.5.2> frontend_1 | npm notice Run `npm install -g npm@7.5.2` to update! frontend_1 | npm notice frontend_1 | yarn run v1.22.5 frontend_1 | $ react-scripts start frontend_1 | node:internal/modules/cjs/loader:928 frontend_1 | throw err; frontend_1 | ^ frontend_1 | frontend_1 | Error: Cannot find module 'rollup-plugin-babel' frontend_1 | Require stack: frontend_1 | - /frontend/node_modules/workbox-build/build/lib/bundle.js frontend_1 | - /frontend/node_modules/workbox-webpack-plugin/build/generate-sw.js frontend_1 | - /frontend/node_modules/workbox-webpack-plugin/build/index.js frontend_1 | - /frontend/node_modules/react-scripts/config/webpack.config.js frontend_1 | - /frontend/node_modules/react-scripts/scripts/start.js frontend_1 | at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15) frontend_1 | at Function.Module._load (node:internal/modules/cjs/loader:769:27) frontend_1 | at Module.require (node:internal/modules/cjs/loader:997:19) frontend_1 | at require (node:internal/modules/cjs/helpers:92:18) frontend_1 | at Object.<anonymous> (/frontend/node_modules/workbox-build/build/lib/bundle.js:22:15) frontend_1 | at Module._compile (node:internal/modules/cjs/loader:1108:14) frontend_1 | at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10) frontend_1 | at Module.load (node:internal/modules/cjs/loader:973:32) frontend_1 | at Function.Module._load (node:internal/modules/cjs/loader:813:14) frontend_1 | at Module.require (node:internal/modules/cjs/loader:997:19) { frontend_1 | code: 'MODULE_NOT_FOUND', frontend_1 | requireStack: [ frontend_1 | '/frontend/node_modules/workbox-build/build/lib/bundle.js', frontend_1 | '/frontend/node_modules/workbox-webpack-plugin/build/generate-sw.js', frontend_1 | '/frontend/node_modules/workbox-webpack-plugin/build/index.js', frontend_1 | '/frontend/node_modules/react-scripts/config/webpack.config.js', frontend_1 | '/frontend/node_modules/react-scripts/scripts/start.js' frontend_1 | ] frontend_1 | } frontend_1 | error Command failed with exit code 1. frontend_1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

FROM node:latest WORKDIR /frontend COPY . /frontend COPY package.json /frontend ENV PATH /frontend/node_modules/.bin:$PATH RUN npm install RUN npm install react-scripts EXPOSE 3000 CMD ["npm", "start"]

で解決いたしました。

投稿2021/02/11 22:09

BoKuToTuZenU

総合スコア51

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

次のようにしてはどうでしょうか

Dockerfile

1FROM node 2 3WORKDIR /frontend 4 5COPY . . 6RUN yarn install 7 8EXPOSE 3000 9CMD ["yarn", "run", "start"]

投稿2021/02/04 14:37

mikan3rd

総合スコア220

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問