コンテナの停止、ネットワーク・名前付きボリューム・コンテナイメージ・未定義サービスコンテナをまとめてスマートに削除できないかと3ヶ月くらい考えていたら良いオプションを発見しました。
神のコマンド
$ docker-compose down --volumes --rmi all --remove-orphans
Stopping docker-sample_web_1 ... done
Stopping docker-sample_app_1 ... done
Stopping docker-sample_db_1 ... done
Removing docker-sample_web_1 ... done
Removing docker-sample_app_1 ... done
Removing docker-sample_db_1 ... done
Removing network docker-sample_default
Removing volume docker-sample_db-store
Removing image docker-sample_app
Removing image nginx:1.17.0-alpine
Removing image mysql:8.0.16
docker volume prune
や docker volume ls
で探して docker volume rm
で指定してがんばって削除しなくてよくなったので嬉しいです😊
付録
$ docker-compose down -h
Stops containers and removes containers, networks, volumes, and images
created by `up`.
By default, the only things removed are:
- Containers for services defined in the Compose file
- Networks defined in the `networks` section of the Compose file
- The default network, if one is used
Networks and volumes defined as `external` are never removed.
Usage: down [options]
Options:
--rmi type Remove images. Type must be one of:
'all': Remove all images used by any service.
'local': Remove only images that don't have a
custom tag set by the `image` field.
-v, --volumes Remove named volumes declared in the `volumes`
section of the Compose file and anonymous volumes
attached to containers.
--remove-orphans Remove containers for services not defined in the
Compose file
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
(default: 10)