こんな感じでDockerを使ってReactアプリの開発をしようとしたところ、Drive sharing failed for an unknown reason
というエラーが出てdocker-compose
コマンドの実行に失敗したのでメモしておく。
[エラー概要]
json-serverをバックエンドがわりに一緒に組み込んで、バックエンドAPIの実装を待たずにフロントエンドだけを開発できるようにしたいと考え、この辺りのサイトを参考にしながら、Dockerを使ってReactの開発環境を整えていた。
利用しているDockerのバージョン情報は以下の通り。ちなみにOSはWindows 10 Pro 1809である。
$ docker -v Docker version 19.03.2, build 6a30dfc $ docker-compose -v docker-compose version 1.24.1, build 4667896b
Dockerfile
を作って、docker-compose build
でDockerイメージをビルドして、次の段階に移ろうとしたところで問題が起きた。
> docker-compose run --rm node sh -c “npm install -g create-react-app && create-react-app myapp --typescript" Creating network "docker-myapp_default" with the default driver ERROR: Cannot create container for service node: b'Drive sharing failed for an unknown reason'
[対処法]
Drive sharing failed for an unknown reason
というエラーメッセージで検索すると、GitHubのIssueに行き着いた。
読み進めると、どうやら設定に問題があるらしいことが分かった。
タスクバーからDockerのアイコンを探してクリックして、メニューを表示する。
メニューから「Settings」を選択するとダイアログが表示されるので、左側の一覧から「Shared Drives」を選択する。
今回はCドライブを共有するので、Cドライブにチェックを入れて、右下の「Apply」ボタンをクリックする。
すると、ファイルシステムへのアクセス権を求めるダイアログが表示されるので、Windowsのログインユーザー名とパスワードを入力する。ユーザー名は自動で補完されるため画像では黒塗りにしてある。
ユーザー名とパスワードを入力して「OK」をクリックすると設定は完了である。
改めてdocker-compose run
コマンドを実行すると、今度はうまくいった。
> docker-compose run --rm node sh -c “npm install -g create-react-app && create-react-app myapp --typescript" /usr/local/bin/create-react-app -> /usr/local/lib/node_modules/create-react-app/index.js + create-react-app@3.1.1 added 91 packages from 45 contributors in 16.818s Creating a new React app in /usr/src/app/myapp. Installing packages. This might take a couple of minutes. Installing react, react-dom, and react-scripts... yarn add v1.17.3 [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.9: The platform "linux" is incompatible with this module. info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation. info fsevents@2.0.7: The platform "linux" is incompatible with this module. info "fsevents@2.0.7" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... warning "react-scripts > @typescript-eslint/eslint-plugin@1.13.0" has incorrect peer dependency "eslint@^5.0.0". warning "react-scripts > @typescript-eslint/parser@1.13.0" has incorrect peer dependency "eslint@^5.0.0". [4/4] Building fresh packages... success Saved lockfile. success Saved 15 new dependencies. info Direct dependencies ├─ @types/jest@24.0.18 ├─ @types/node@12.7.4 ├─ @types/react-dom@16.9.0 ├─ @types/react@16.9.2 ├─ react-dom@16.9.0 ├─ react-scripts@3.1.1 ├─ react@16.9.0 └─ typescript@3.6.2 info All dependencies ├─ @types/jest-diff@20.0.1 ├─ @types/jest@24.0.18 ├─ @types/node@12.7.4 ├─ @types/prop-types@15.7.2 ├─ @types/react-dom@16.9.0 ├─ @types/react@16.9.2 ├─ csstype@2.6.6 ├─ eslint-config-react-app@5.0.1 ├─ react-dev-utils@9.0.3 ├─ react-dom@16.9.0 ├─ react-error-overlay@6.0.1 ├─ react-scripts@3.1.1 ├─ react@16.9.0 ├─ scheduler@0.15.0 └─ typescript@3.6.2 Done in 612.70s. We detected TypeScript in your project (src/App.test.tsx) and created a tsconfig.json file for you. Your tsconfig.json has been populated with default values. Success! Created losm at /usr/src/app/myapp Inside that directory, you can run several commands: yarn start Starts the development server. yarn build Bundles the app into static files for production. yarn test Starts the test runner. yarn eject Removes this tool and copies build dependencies, configuration files and scripts into the app directory. If you do this, you can’t go back! We suggest that you begin by typing: cd myapp yarn start Happy hacking!
このあとdocker-compose upコマンドでコンテナを起動して、動作確認まで終えることが出来た。
> docker-compose up Creating docker-myapp_node_1 ... done Attaching to docker-myapp_node_1 node_1 | yarn run v1.17.3 node_1 | $ react-scripts start node_1 | Starting the development server... node_1 | node_1 | ============= node_1 | node_1 | WARNING: You are currently running a version of TypeScript which isescript-estree. node_1 | node_1 | You may find that it works just fine, or you may not.u may not. node_1 | .0 node_1 | SUPPORTED TYPESCRIPT VERSIONS: >=3.2.1 <3.6.0 node_1 | node_1 | YOUR TYPESCRIPT VERSION: 3.6.2 node_1 | node_1 | Please only submit bug reports when using the officially supported version. node_1 | node_1 | ============= node_1 | Files successfully emitted, waiting for typecheck results... node_1 | Compiled successfully! node_1 | node_1 | You can now view losm in the browser. node_1 | node_1 | Local: http://localhost:3000/ node_1 | On Your Network: http://172.19.0.2:3000/ node_1 | node_1 | Note that the development build is not optimized. node_1 | To create a production build, use yarn build. node_1 |
[まとめ]
- エラーメッセージが出たらとにかくググる、できれば英語で
- Docker for Windowsで「Drive sharing failed for an unknown reason」のエラーが出たときはドライブの共有設定を見直す
Twitterで、エラーメッセージでググった時にStackOverflowが出たら当たり、GitHubのIssueが出たらハズレというような意見を見かけたが、必ずしもそうではないと思う。
今回のようにクローズされて解決済みのGitHub Issueも多いので、諦めずに読んでみるとなんとかなるかも。ならないかも。