139
112

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 5 years have passed since last update.

Docker の容量不足解決(docker system prune)

Posted at

Docker の容量不足解決(docker system prune)

定期的に image を整理していたが、docker pullno space left on deviceのエラーメッセージが表示。volume の整理も必要だった。

failed to register layer: Error processing tar file(exit status 1): write /tmp/xxxxx.tar.gz: no space left on device

1. Dockerのディスク利用状況を確認

docker system dfでディスク容量を確認したところ、Local Disk が解放されておらず、ゴミが残っていた。

# Docker のディスク利用状況を確認
> docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              0                   0                   0B                  0B
Containers          0                   0                   0B                  0B
Local Volumes       20                  0                   24.84GB             24.84GB (100%)
Build Cache         0                   0                   0B                  0B

# -v オプションで詳細表示
> docker system df -v
Images space usage:

REPOSITORY          TAG                 IMAGE ID            CREATED ago         SIZE                SHARED SIZE         UNIQUE SiZE         CONTAINERS

Containers space usage:

CONTAINER ID        IMAGE               COMMAND             LOCAL VOLUMES       SIZE                CREATED ago         STATUS              NAMES

Local Volumes space usage:

VOLUME NAME                                                        LINKS               SIZE
2377861222d0a9f4c17b0c8be0fcfb6007349e9dc49068101d6c7154363f4976   0                   0B
52277ff5bdde3f484517af28f16816a996fafafd5f9eeaddbb8e59be0c60e796   0                   0B
5983a937123b4d17fdae4b4cb8c08c70748561c08d11aa5c3034f38541da7179   0                   708.3MB
6f0262bd4dd1066ec7a987faf6da9df982fa5ea0a80d632941b72344bc878438   0                   0B
a73a80634dead8ddcab26efaea9e5797ad45cc294ebe7a87c8becdf409aa3c37   0                   0B
baf1805f456114edbaf028c5bc0bd67f389ceb50bc608f2a5fd5adf954058617   0                   2.603GB
c2e923a9c223eed4bfe6defe557e440caef6cb7365c5649ea1725cee6af9e08a   0                   2.904GB
cf18c04e5215684308d4cee58c21b95eec5381bdbe5208eb2a48fe377d040804   0                   1.603GB
19ecc06a2c2d6132580abfa4c413cb774da14f7e938fb338a91777b10518066c   0                   0B
44f790154c7c201fdd5c1af3ff9201daf7250877182f0cd15f8728d699a0cb1f   0                   0B
82e87dc844c920dd72a76da76595993bd5ff5f86477415030acf2e748cfa1f28   0                   0B
a0b5acb21756b67d94b5144ac0b5cf04776b2ca0b4ec62fcd2c2c817c92c4c04   0                   0B
b9479d8e3c39e4de77a9d55593f73c494be9119586308521c1a6546fde8d7fb0   0                   0B
1497355c88a433d4fe13a567d9ca0153bd7b97a8a9c1859a94f40282261f80c3   0                   4.099GB
1f716a79a3671e43993b2634332d116ecb081a83d50e779f66ed99960d03b2e8   0                   214.6MB
211540c7f99f1e12c56d30b51a3728c21184df6c24157c268c1021d9247cb483   0                   1.042GB
2a01ea022c20ee208be8ab04ecab82af49dd4c2f798d87dcda6a9372844eea7a   0                   7.565GB
01be05291c0c111c95accf0e2405e7b36ba3107ea0b105bda8df44de10efaf6a   0                   4.099GB
3b822d8dbbee8f7735ffdc95d7a9b7a81964803e56993d2d250e3fae4fd064f4   0                   0B
bbb13ca2318b3259601dd035dc1ede9344eacd485c459335ad0941137dfc2c91   0                   0B

Build cache usage: 0B

2. Local Volumes の整理

docker system pruneは、Docker のバージョンによって動作が異なる。
docker docs - docker system prune
https://docs.docker.com/engine/reference/commandline/system_prune/

Docker 17.06.1以降

不要な volume を削除するには、--volumesオプションの付与が必要。

# 不要なコンテナ/ネットワーク/イメージ/ボリュームの一括削除
> docker system prune -a --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 images without at least one container associated to them
        - all build cache
Are you sure you want to continue? [y/N]

オプション--volumesなしで実行すると、WARNING に volumes の記載がない。

# 不要なコンテナ/ネットワーク/イメージの一括削除(ボリュームは対象外)
> docker system prune -a
WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all images without at least one container associated to them
        - all build cache
Are you sure you want to continue? [y/N]

Docker 17.06.1 より古いバージョン

docker system prune -aで、不要なコンテナ/ネットワーク/イメージ/ボリュームを一括削除する。

3. 個別に削除する場合

# 不要コンテナの一括削除
> docker container prune

# 不要ネットワークの一括削除
> docker network prune

# 不要イメージの一括削除
> docker image prune

# 不要ボリュームの一括削除
> docker volume prune

確認環境では、整理する必要があるのはボリュームのみであるため、以下で実施。

> docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
2377861222d0a9f4c17b0c8be0fcfb6007349e9dc49068101d6c7154363f4976
5983a937123b4d17fdae4b4cb8c08c70748561c08d11aa5c3034f38541da7179
a73a80634dead8ddcab26efaea9e5797ad45cc294ebe7a87c8becdf409aa3c37
cf18c04e5215684308d4cee58c21b95eec5381bdbe5208eb2a48fe377d040804
a0b5acb21756b67d94b5144ac0b5cf04776b2ca0b4ec62fcd2c2c817c92c4c04
b9479d8e3c39e4de77a9d55593f73c494be9119586308521c1a6546fde8d7fb0
bbb13ca2318b3259601dd035dc1ede9344eacd485c459335ad0941137dfc2c91
c2e923a9c223eed4bfe6defe557e440caef6cb7365c5649ea1725cee6af9e08a
2a01ea022c20ee208be8ab04ecab82af49dd4c2f798d87dcda6a9372844eea7a
44f790154c7c201fdd5c1af3ff9201daf7250877182f0cd15f8728d699a0cb1f
52277ff5bdde3f484517af28f16816a996fafafd5f9eeaddbb8e59be0c60e796
6f0262bd4dd1066ec7a987faf6da9df982fa5ea0a80d632941b72344bc878438
82e87dc844c920dd72a76da76595993bd5ff5f86477415030acf2e748cfa1f28
baf1805f456114edbaf028c5bc0bd67f389ceb50bc608f2a5fd5adf954058617
01be05291c0c111c95accf0e2405e7b36ba3107ea0b105bda8df44de10efaf6a
1497355c88a433d4fe13a567d9ca0153bd7b97a8a9c1859a94f40282261f80c3
19ecc06a2c2d6132580abfa4c413cb774da14f7e938fb338a91777b10518066c
3b822d8dbbee8f7735ffdc95d7a9b7a81964803e56993d2d250e3fae4fd064f4
1f716a79a3671e43993b2634332d116ecb081a83d50e779f66ed99960d03b2e8
211540c7f99f1e12c56d30b51a3728c21184df6c24157c268c1021d9247cb483

Total reclaimed space: 24.84GB

# Docker のディスク利用状況を再確認
> docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              0                   0                   0B                  0B
Containers          0                   0                   0B                  0B
Local Volumes       0                   0                   0B                  0B
Build Cache         0                   0                   0B                  0B
139
112
2

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
139
112

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?