Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Windows10 + Vagrant + Virtual Box + docker + node.js で npm install すると text file is busy となるエラーに対処したメモ

More than 1 year has passed since last update.

結論

ファイル共有でnode_modulesがうまく作られないのが原因。
node_modulesディレクトリはコンテナ内のみに隔離することで対応。

動作環境

  • windows10
  • vagrant2.1.1
  • virtualbox5.2.12
  • ubuntu-18.04
  • Docker version 18.05.0-ce, build f150324
  • docker-compose version 1.21.2, build a133471

エラーメッセージ

root@06ceade09ca6:/app# npm install
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
npm WARN rollback Rolling back ansi-regex@2.1.1 failed (this is probably harmless): ETXTBSY: text file is busy, unlink '/app/node_modules/ansi-regex/package.json.3358036472'
npm WARN rollback Rolling back acorn-dynamic-import@3.0.0 failed (this is probably harmless): ETXTBSY: text file is busy, unlink '/app/node_modules/acorn-dynamic-import/package.json.1207675771'
'/app/node_modules/budo/node_modules/minimist/package.json.1923057578'
npm WARN app@1.0.0 No repository field.

npm ERR! path /app/node_modules/array-find-index/package.json.2479725784
npm ERR! code ETXTBSY
npm ERR! errno -26
npm ERR! syscall rename
npm ERR! ETXTBSY: text file is busy, rename '/app/node_modules/array-find-index/package.json.2479725784' -> '/app/node_modules/array-find-index/package.json'

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-07-02T13_59_51_752Z-debug.log

対応方法

以下のように、コンテナのボリュームを指定してやることで、node_modulesをコンテナ内のみにおいておき、ホスト側のディレクトリを使わないようにできる。

docker-compose.yml
version: '3'
services:
  test:
    build: ./test
    volumes:
      - ../src:/app
      - /app/node_modules # コンテナ内のnode_moduleをvolumesに登録

参考

Docker と node_modules と Volume Trick
DockerでのNodeアプリ構築で学んだこと

hibohiboo
Javascriptが好きです。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away