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?

docker compose down が失敗して docker rm -f で解決した話(ゾンビコンテナ)

Posted at

発生した事象

$ docker compose down -v

実行時に以下のエラーが発生。

Error response from daemon:
cannot stop container:
tried to kill container, but did not receive an exit event

コンテナが停止できず、down が失敗する状態。

原因

Docker がコンテナを停止(SIGTERM / SIGKILL)しようとしたが、

  • 「コンテナが終了した」という exit event を受信できなかった
  • Dockerの管理情報と実体の状態がズレている

結果として、
Dockerから見ると「動いている扱い」だが、制御不能なコンテナ(状態不整合コンテナ) になっていた。

なぜ docker compose down は失敗するのか

docker compose down は以下を保証しようとする:

  • コンテナを正常に stop
  • exit event(終了通知)を確認
  • コンテナを削除

今回のように exit event が返ってこない 場合、
「停止できたと確認できない」ためエラーになる。

解決策

強制削除を実行

$ docker rm -f eb208c9b5ba1(コンテナID)

なぜこれで直る?
docker rm -f は:

  • コンテナの生死確認を待たない
  • Dockerの管理DBからコンテナ情報を即削除する

そのため、
停止できない・状態がおかしいコンテナでも除去可能。

downrm -f の違い(ざっくり)

コマンド 挙動
docker compose down 正常停止を確認してから削除
docker rm -f 強制終了して即削除(力技)

まとめ

  • tried to kill container, but did not receive an exit event
    Dockerの状態不整合あるある
  • データ破損やDocker故障ではないことがほとんど
  • docker rm -f は正しい対処
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?