0
0

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のお片付け with Windows

0
Last updated at Posted at 2025-09-14

まえがき

ゲーム&開発用 WindowsPCでCドライブ(1TB)が満杯になってしまいました。

とりあえずWinDirStatしたところ、Rancher Desktopのディレクトリが120GBを占領していて諸々対処をしたのでログとして残しておきます。

TL;DR

  • 定期的にpruneしましょう
  • pruneはimage, container, volumeだけでなくbuild cacheもpruneしましょう
  • Windowsではdiskpartで仮想ディスクを縮小する必要があります

環境情報

OS: Windows 11 Pro 24H2
Docker: Rancher Desktop 1.20.0

作業ログ

観測する

WinDirStatでCを見てみると、C:\Users\<username>\AppData\Local\rancher-desktop\distro-data\ext4.vhdxにとんでもない容量が食われていることが分かります。これが今回の処理対象です。

image.png

pruneする

今回の本丸です。image, containerはしばしばpruneしていたのですが、長期にわたりビルドキャッシュをpruneしていなかったのが原因でした。ということでpruneしていきます。

$ docker buildx prune
WARNING! This will remove all dangling build cache. Are you sure you want to continue? [y/N] y
ID                                              RECLAIMABLE     SIZE            LAST ACCESSED
hofsxk8xwqwvkndroz56olykm*                      true            233.1kB         3 weeks ago
...
Total:  93.26GB

これで93GBが解放されました。

しかし、これだけではext4.vhdxのサイズは縮小しません。Diskpartで縮小する必要があります。

diskpart

diskpartでvdiskになっているext4.vhdxをマウントして解放された分仮想ディスクを縮小させます。

具体的には以下の2行を実行します。

select vdisk file="C:\Users\<username>\AppData\Local\rancher-desktop\distro-data\ext4.vhdx"
compact vdisk

実際のコンソール表示を交えるとこんな感じです。

Microsoft DiskPart version 10.0.26100.1150

Copyright (C) Microsoft Corporation.
On computer: <PCNAME>

DISKPART> select vdisk file="C:\Users\<username>\AppData\Local\rancher-desktop\distro-data\ext4.vhdx"

DiskPart successfully selected the virtual disk file.

DISKPART> compact vdisk

  100 percent completed

DiskPart successfully compacted the virtual disk file.

結果

だいぶ小さくなりました。

image.png

まとめ

Rancher Desktopが使用するビルドキャッシュ等を詰めた仮想ディスクが肥大化していたので、適切なpruneとdiskpartで縮小しました。
(自動化したいけどdiskpartが管理者権限を要求するし、時々手でたたかないといけないので恒久的対策にならない所が痒い…)

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?