Docker Tips

停止中のコンテナ一覧を表示

$ docker ps -f status=exited
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
f629f04e6797        ubuntu              "/bin/bash"         3 seconds ago       Exited (0) 2 seconds ago                       romantic_knuth
...

起動中のコンテナを停止

$ docker stop $(docker ps -q)
1819ed18e593
6ca5f53e1cf7
9736cd1fc5c4
...

コンテナを全削除

$ docker stop $(docker ps -q)
1819ed18e593
6ca5f53e1cf7
9736cd1fc5c4
...

$ docker rm $(docker ps -aq)
1819ee18e593
6ca5f93e1cf7
9735cd1fc5c4
...

未使用イメージを削除  API 1.25+

$ docker image prune -a
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
Deleted Images:
untagged: ubuntu:latest
untagged: ubuntu@sha256:fbaf303d18563e57a3c1a0005356ad102509b60884f3aa89ef9a90c0ea5d1212
deleted: sha256:ec61d13ca5666651ff092b89d46ae958d81c7f3d387ed91ae5c530a38b9896e2
deleted: sha256:608a8923432886028a0216da5e4dfcf384e08530e90e4d5d1502cdc5e57a118f
deleted: sha256:095432e3f1f03903e167576b58357907b4c6f272c54825404d94a7fe4c8b2877
...

Total reclaimed space: 1.268GB

未使用ボリュームを削除  API 1.25+

$ 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:
f1d9c2c2796ef0bd7f6b246e630a9b2ba2d295b1cbb866994163c50924a8f434
...

Total reclaimed space: 0B

未使用データを削除  API 1.25+

$ docker system prune
WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
9c2fc6a6aedb049f6b130cd06651ff05f9b5506c45f19b1931b7503bf7527e70
9612af43cbc18ad6645c2a0ceaccd0eeb100a2e0a4458bdbb0750a1e2227a562
...

Deleted Images:
deleted: sha256:39ed8a33acbfc17a5323737bab66cb1add06eef80fbb875137c808b9cc7a147b
deleted: sha256:d55fe535f3bd5bd116d2f8da2060694469f67936b31be7ba2b630108b09691f4
deleted: sha256:27b966e232a709c9e46ba45eaf17bb10002e579962e4ec84d0693040db212770
...

Total reclaimed space: 154.8MB

ディスク使用量を表示  API 1.25+

$ docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              7                   5                   1.515GB             909.2MB (60%)
Containers          7                   3                   96.3MB              41.4MB (42%)
Local Volumes       1                   1                   55.98MB             0B (0%)
Build Cache                                                 0B                  0B