LoginSignup
0
0

More than 1 year has passed since last update.

Dockerのお掃除

Posted at

はじめに

Dockerを使って環境を構築しようとした時にimageのpullがうまくいかなかったのでサーバ内の容量を確認/最適化した

やりたいこと

現在使われていないものを削除することでDockerの容量を軽くする

何をお掃除するのかを確認

docker system df

$ docker system df 
>>
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          3         1         12.56GB   12.52GB (99%)
Containers      1         0         34.4kB    34.4kB (100%)
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B

imageの容量が大きく,再利用可能な領域(RECLAIMABLE)が大きいことがわかる.

使われてないものを削除

docker system prune

  • 止まってるコンテナ、使われてないボリューム、使われてないネットワーク、使われてないイメージを削除する
  • ドキュメント
$ docker system prune
WARNING! This will remove:
    - all stopped containers
    - all volumes not used by at least one container
    - all networks not used by at least one container
    - all dangling images
Are you sure you want to continue? [y/N] y
...

個別でimage, containerの削除

imageを削除するときはまずcontainerから削除する
containerの削除: docker rm [container ID]
imageの削除: docker rmi [image ID]

[補足]containerを一括削除

container IDの一覧を取得: docker ps -a -q
containerの一括削除: docker rm `docker ps -a -q`

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