4
1

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】コンテナのライフサイクルを押さえよう

Last updated at Posted at 2025-09-08

簡単におさらい

Docker Containerとは

  • Docker Imageから作られる一つの隔離された環境だよ
  • 1コンテナ = 1プロセスだよ
  • 1つのコマンドをフォアグラウンドで動かすようにできているよ(超大事)
    • そのコマンドの実行がフォアグラウンドで終了するまでコンテナは起動しているといえるよ

コンテナのライフサイクル

コンテナは主に5つの状態を遷移します

1. Image状態

  • まだコンテナが作られていないことを表します。

2. Running状態

  • コンテナが起動状態であることを示します。
  • Dockerfile の CMD または ENTRYPOINT で指定したコマンドがフォアグラウンドで動いている間は Running の状態です。
  • 例:docker run -it ubuntu bashdocker run -p 8080:80 nginx

3. Paused状態

  • コンテナが一時停止した状態です。
  • docker pause <コンテナID> で一時停止できます。
  • 基本的にコンテナが勝手に Paused になることはなく、ユーザーの明示的操作が必要です。
  • docker unpause <コンテナID> で起動(Running)状態に戻ります。

4. Stopped状態

  • コンテナが停止した状態です(= プロセスはすべて終了・解放)。
  • 正常終了でも異常終了でも、終了したコンテナは Stopped に遷移します。
  • 先述のとおり、フォアグラウンドで動いていたデフォルトコマンドが終了するとコンテナも終了し、Stopped になります。

5. Deleted状態

  • Stopped 状態のコンテナを削除できます。
  • docker rm <コンテナID> でコンテナを削除します。
  • Stopped ではないコンテナ(起動中・一時停止中)は削除できません。

image.png

画像は以下より引用
https://y-ohgi.com/introduction-docker/2_component/container/

4
1
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?