LoginSignup
6
1

More than 1 year has passed since last update.

Docker で "device or resource busy" と言われ rm できなかったら

Posted at

やろうとしたことと生じた問題

php コンテナを立ちあげ,コンテナ内部をこねくりまわしている途中, node_modules(Javascript のモジュールが入っているディレクトリ) を消したくなった。

$ rm -rf node_modules
> rm: cannot remove ‘./node_modules’: Device or resource busy

Device or resource busyが原因でrm削除できない!!解決法はmountやmvではなく、〇〇だ!!

この記事に基づき,以下を試してみた。

$ lsof

lsof, fuser は,コンテナにインストールされていない場合 command not found となります。
Debian 系なら apt-get update && apt-get install lsof
CentOS系なら yum install lsof
でパッケージをインストールしてください。

この php-fpm を kill すると,コンテナ自体が止まってしまいます。しかも,php-fpm が node_modules を使用しているわけではありません。

何が原因だったのか

node_modules を volume mount していたことが原因でした。
コンテナ内部に集中していたため,盲点でした。

docker-compose.yml
workspace:
    image: php:7.4-fpm-buster
    ports:
      - 9000:9000
    volumes:
      - type: volume
        source: node_modules-store
        target: /var/www/html/node_modules

どう解決するか

rm -rf したいときだけ volume mount を外せば良いです。

docker-compose.yml
workspace:
    image: php:7.4-fpm-buster
    ports:
      - 9000:9000
    volumes:
      #- type: volume
      #  source: node_modules-store
      #  target: /var/www/html/node_modules
$ docker compose down # コンテナを廃棄してマウントをリセットする
$ docker compose up php -d
6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1