読者です 読者をやめる 読者になる 読者になる

Taker's インフラ関連技術調査ログ

インフラ関連についての調査メモです。

Docker systemコマンドとclean-up系コマンド

Docker 1.13でCLIが改善されたとの記事があったのでお試し。

https://www.infoq.com/jp/news/2017/02/docker-1.13

docker system - Docker

Docker System

docker system df

Dockerのディスク利用状況がわかる。便利。

$ docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              24                  2                   9.816 GB            9.205 GB (93%)
Containers          3                   0                   0 B                 0 B
Local Volumes       3                   3                   318.9 MB            0 B (0%)

docker system events

サーバーからのリアルタイムイベントを取得して標準出力してくれる。 オプション無しだとログが長くて読みにくいのでfilterして使うのが良さそう。

$ docker system events
2017-02-11T19:32:45.900852754+09:00 network create 1560fdef4fcd98b68e64dc5815b9616e77167ce1ba8d0d899c680a1e8ddb8ef2 (name=ultimatecatalogapi_default, type=bridge)
2017-02-11T19:32:45.937009381+09:00 volume create ultimatecatalogapi_uc-data (driver=local)
2017-02-11T19:32:46.352153980+09:00 container create 84d93c1fc07a683ec59887202fd4fb45b7ff8894688bfd7dad56c5c7b55af1ee (com.docker.compose.config-hash=996c535a97366837fb156707e1cf1a55346d5e9adc522cf1a78a6b0970393348, com.docker.compose.container-number=1, com.docker.compose.oneoff=False, com.docker.compose.project=ultimatecatalogapi, com.docker.compose.service=api, com.docker.compose.version=1.11.1, image=ultimatecatalogapi_api, name=ultimatecatalogapi_api_1)
2017-02-11T19:32:46.368757935+09:00 container attach 84d93c1fc07a683ec59887202fd4fb45b7ff8894688bfd7dad56c5c7b55af1ee (com.docker.compose.config-hash=996c535a97366837fb156707e1cf1a55346d5e9adc522cf1a78a6b0970393348, com.docker.compose.container-number=1, com.docker.compose.oneoff=False, com.docker.compose.project=ultimatecatalogapi, com.docker.compose.service=api, com.docker.compose.version=1.11.1, image=ultimatecatalogapi_api, name=ultimatecatalogapi_api_1)
2017-02-11T19:32:46.443896827+09:00 network disconnect 1560fdef4fcd98b68e64dc5815b9616e77167ce1ba8d0d899c680a1e8ddb8ef2 (container=84d93c1fc07a683ec59887202fd4fb45b7ff8894688bfd7dad56c5c7b55af1ee, name=ultimatecatalogapi_default, type=bridge)
2017-02-11T19:32:46.592015158+09:00 container create 8c6e0aac2ec66d23d8bb00895f7cba2a69963a9c199889613c6f9221006b0968 (com.docker.compose.config-hash=d8d867edf8af8cda04ecd661b84a4183b81c7575612e608c533c8d4e0be3fb39, com.docker.compose.container-number=1, com.docker.compose.oneoff=False, com.docker.compose.project=ultimatecatalogapi, com.docker.compose.service=mongo, com.docker.compose.version=1.11.1, image=mongo:latest, name=ultimatecatalogapi_mongo_1)

docker system info

システム情報を表示

docker system prune

未使用データの削除。停止中のコンテナの削除などをしてくれる。使い方を間違えなければ便利。

ボリュームの削除

未使用のボリュームの削除

$ docker volume prune
WARNING! This will remove all volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
a22a726badc76f67e9bf6414c3ee9f4104a1ad9caa2fbc4ac8d191f6b778a345
a5af6749f56651087d7fb2b1896e624486fb40fd8fce0e3153671eb35363ed24
fb6974503d635b5f9d97a3951901794acdd6afd279209e95da7f15ffb91b28ae
ultimatecatalogapi_uc-data
4426cb4bdd449b750f29c83a835bd211bd664fd27e69644616ddb81b09a2557d
a20b31b370e79a43c7bb9b00243b83016dc938621245f119e231f520325b4473
d94fab1718e74c35b1970a63e4c61060f4db979b9919d63c4c04aef9ca908e47

Total reclaimed space: 641.6 MB

イメージの削除

タグ付けされていないイメージを削除

$ docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Deleted Images:
deleted: sha256:1ff2f4c46f286b04e7a932450aed4138349a477f558ded55fcecb5fd4b5cba66
deleted: sha256:bdcd065ab7de14bf53579ac02912701a44e25981e20464cec6de1e20c5c5baee
deleted: sha256:09f28b3a116d6c392851fff8b65a29f153ecdc8442acbb02b0461ce97aa78bb3
deleted: sha256:fabd7e17fbdd44ee2821e345d7ca8d423cd2c3dd24713bf789dfa4995814688d
deleted: sha256:e85ffe4667da329053f6a47b775dcf790d7a957adc7bed72d87a6284bad7dbd6
deleted: sha256:22263a689937489bf399e05edd9682618319e6cb3801b6ec42d9c7415725033d
deleted: sha256:5940666d2088bdb774ac498d4adf7e754b81318641924efab95cf1ed3256faa0

Total reclaimed space: 278.5 MB
/* Responsive: yes */