3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

dockerで"ENOSPC: no space left on device, write"エラー発生したら、docker system prune か docker system prune --volumesしろ

Last updated at Posted at 2022-10-13

エラー詳細

dockerでnext.jsのリポジトリを起動した際、以下「容量いっぱいだよお」みたいなエラー発生

$ docker-compose build --no-cache && docker-compose up -d[+] Running 2/2
 ⠿ Container hoge-front_1  Removed                                                                                                                                                                                                                                                                                                    1.5s
 ⠿ Network hoge-front_default                 Removed                                                                                                                                                                                                                                                                                                    0.0s
[+] Building 40.7s (10/11)
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                                                                                   0.0s
 => => transferring dockerfile: 289B                                                                                                                                                                                                                                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                                                                      0.0s
 => => transferring context: 74B                                                                                                                                                                                                                                                                                                                                       0.0s
 => [internal] load metadata for docker.io/library/node:16.6                                                                                                                                                                                                                                                                                                           1.9s
 => [auth] library/node:pull token for registry-1.docker.io                                                                                                                                                                                                                                                                                                            0.0s
 => CACHED [1/6] FROM docker.io/library/node:16.6@sha256:1a658b891340da03322eec3d95d48de319a3b8dda0f1cc4cf7aa46dd20e4a198                                                                                                                                                                                                                                              0.0s
 => [internal] load build context                                                                                                                                                                                                                                                                                                                                      1.2s
 => => transferring context: 63.46MB                                                                                                                                                                                                                                                                                                                                   1.2s
 => [2/6] RUN mkdir -p /usr/src/app                                                                                                                                                                                                                                                                                                                                    0.6s
 => [3/6] WORKDIR /usr/src/app                                                                                                                                                                                                                                                                                                                                         0.0s
 => [4/6] COPY package.json yarn.lock /usr/src/app/                                                                                                                                                                                                                                                                                                                    0.1s
 => ERROR [5/6] RUN yarn install                                                                                                                                                                                                                                                                                                                                      37.4s
------
 > [5/6] RUN yarn install:
#0 0.523 yarn install v1.22.5
#0 0.598 [1/4] Resolving packages...
#0 0.759 [2/4] Fetching packages...
#0 26.02 error https://registry.yarnpkg.com/emojis-list/-/emojis-list-3.0.0.tgz: Extracting tar content of undefined failed, the file appears to be corrupt: "ENOSPC: no space left on device, write"
#0 26.02 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
#0 26.03 error https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-12.1.5.tgz: Extracting tar content of undefined failed, the file appears to be corrupt: "ENOSPC: no space left on device, write"
#0 26.03 error https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-12.1.5.tgz: Extracting tar content of undefined failed, the file appears to be corrupt: "ENOSPC: no space left on device, write"
#0 26.03 error https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-12.1.5.tgz: Extracting tar content of undefined failed, the file appears to be corrupt: "ENOSPC: no space left on device, write"
#0 26.07 error https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-12.1.5.tgz: ENOSPC: no space left on device, write
------
failed to solve: executor failed running [/bin/sh -c yarn install]: exit code: 1
[+] Running 2/2
 ⠿ Network hoge-front_default                 Created                                                                                                                                                                                                                                                                                                    0.1s
 ⠿ Container hoge-front-1  Started

結論

$ docker system prune

か、

$ docker system prune --volumes

を実行し再度ビルドすれば解決する。

原因

dockerの容量がいっぱいなのが原因
解決前はImagesが100%近くになっており、ビルドするスペースがない。

docker system df                                                                                                                                                                                                                                               
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          43        2         48.46GB   46.82GB (96%)
Containers      2         2         118B      0B (0%)
Local Volumes   8         2         3.237GB   2.606GB (80%)
Build Cache     231       0         63.65MB   63.65MB

コマンド実行することで、45GBも空き容量が増える

注意!! volumeを削除してしまうので、dbコンテナに大事なデータがあったりすると削除されてしまうのでヤバい
その場合は、docker system pruneのみ実行するか、不要なコンテナ指定して削除する等で対応。

docker system prune --volumes                                                                                                                                                                                                                                  
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all volumes not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] y
Deleted Containers:
6444e3113f39539bc8ef2fff36064e93bb761c93d09386d6b7b6ff5771b98f1c

Deleted Networks:
learn-go_default

Deleted Volumes:
6c2aa17276d7d56085d28d08bb411514494a5676c50ed4775728d69b4f39d0b8
9bddd33d78a341ff844c6c8449391098f26f17f2f9cb757e66f20e634ecd9cb8

Deleted Images:
deleted: sha256:bc22a6a6082e48f4d8e9c4d1dc2dd344a69abe8971603d502d78f544bc57e0b8
deleted: sha256:54ea0ef55dc416251b54e5db13f5d28a7d6ea9ca8baaef23287aafa98ec9faf5
deleted: sha256:8c15a0dd828a75d522d03264951568fb0003fed6e3fc9e0c45647ca139210570


---<省略>---

Total reclaimed space: 45.03GB ⇐45GBも空き容量が増えた

再度dockerビルドするとちゃんとエラー発生せずに起動

$ docker-compose build --no-cache && docker-compose up -d                                                                                                                                                                                                    
[+] Building 77.5s (12/12) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                                                                                   0.0s
 => => transferring dockerfile: 32B                                                                                                                                                                                                                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                                                                      0.0s
 => => transferring context: 34B                                                                                                                                                                                                                                                                                                                                       0.0s
 => [internal] load metadata for docker.io/library/node:16.6                                                                                                                                                                                                                                                                                                           1.6s
 => [auth] library/node:pull token for registry-1.docker.io                                                                                                                                                                                                                                                                                                            0.0s
 => CACHED [1/6] FROM docker.io/library/node:16.6@sha256:1a658b891340da03322eec3d95d48de319a3b8dda0f1cc4cf7aa46dd20e4a198                                                                                                                                                                                                                                              0.0s
 => [internal] load build context                                                                                                                                                                                                                                                                                                                                      1.4s
 => => transferring context: 63.46MB                                                                                                                                                                                                                                                                                                                                   1.4s
 => [2/6] RUN mkdir -p /usr/src/app                                                                                                                                                                                                                                                                                                                                    0.7s
 => [3/6] WORKDIR /usr/src/app                                                                                                                                                                                                                                                                                                                                         0.0s
 => [4/6] COPY package.json yarn.lock /usr/src/app/                                                                                                                                                                                                                                                                                                                    0.1s
 => [5/6] RUN yarn install                                                                                                                                                                                                                                                                                                                                            60.3s
 => [6/6] COPY . /usr/src/app                                                                                                                                                                                                                                                                                                                                          0.2s
 => exporting to image                                                                                                                                                                                                                                                                                                                                                13.7s
 => => exporting layers                                                                                                                                                                                                                                                                                                                                               13.7s
 => => writing image sha256:cb1c9ca06f89a429032b118d1773fcc671b33fdc16cbaecb5281cea7be6c976a                                                                                                                                                                                                                                                                           0.0s
 => => naming to docker.io/library/nextjs_dev_builder:16.6.0                                                                                                                                                                                                                                                                                                           0.0s
[+] Running 1/1
 ⠿ Container hoge-front-1  Started

なぜ容量がいっぱいになったのか

開発期間が長く、以下のビルドコマンドを実行するたびにどんどんvolumeが増えてったため

docker-compose build --no-cache && docker-compose up -d 

その他

docker imageに名前?タグ?をつけるとvolumeが増えないらしい?(未調査)

感想

このエラー発生してたけど気にせず開発してたら新規作成したpost/[id]ページが404になって色々調べても解決せずかなり長時間沼ってた。
ちゃんとエラー発生してたら調べようね!

3
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?