LoginSignup
0
0

More than 1 year has passed since last update.

EC2でDockerを使っているとき、no space left on deviceとでたときの改善方法

Last updated at Posted at 2021-05-04

自作アプリに新たなgemをインストールして、ec2で
docker-compose buildをしたとき、
no space left on deviceでた。

解決方法

まず、どのファイルが容量をくっているのかみました。

[myuser@ip-172-31-2-37 goal_tree]$ find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n
      1 .browserslistrc
      1 .dockerignore
      1 .env
      1 .gitattributes
      1 .gitignore
      1 .ruby-version
      1 .vscode
      1 Dockerfile
      1 Gemfile
      1 Gemfile.lock
      1 README.md
      1 Rakefile
      1 babel.config.js
      1 config.ru
      1 docker-compose.yml
      1 dump.sql
      1 entrypoint.sh
      1 package-lock.json
      1 package.json
      1 postcss.config.js
      1 storage
      1 vendor
      1 yarn.lock
      1 クラス図.md
      1 ポートフォリオ コンセプトの整理.md
      1 機能設計.md
      2 containers
      2 lib
      3 log
      8 bin
     18 db
     27 test
     37 config
     59 public
     87 app
    303 .git
  10375 tmp
  16182 node_modules

node_modulesがダントツで多い。

現段階では、.dockerignoreにnode_modulesを入れていなかったので、
buildするときに、node_modulesもbuildするようになっていたから、容量くっているのでは?という仮説を立てました。

.dockerignoreとは

Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context. If this file exists, the CLI modifies the context to exclude files and directories that match patterns in it. This helps to avoid unnecessarily sending large or sensitive files and directories to the daemon and potentially adding them to images using ADD or COPY.

イメージをbuildするときに、.dockerignoreに書いてあるものは除外してくれる。
メリットとしては、大きなファイルや機密性の高いファイルをデーモンに送信したり、イメージを追加することがなくなる。

今回の場合、node_modulesのように大きいファイルとかをデーモンに送信しなくてよくなるので、イメージの容量が減るかなと。

ですが、書きすぎると逆にbuildに時間がかかることもあるみたいです。

参考:

.dockerignoreにnode_modulesをかいてみる

.dockerignore
tmp/*
log/*
.git
containers
## ここを追記
node_modules

無事エラーが出ず、buildできるようになりました。

0
0
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
0
0