Docker
  • Introduction
    • What is Virtualization?
      • What is a Hypervisor?
      • Microsoft Hyper-V
    • What is Containerization?
      • What is docker?
      • What is a container image?
      • When to use containers?
      • When not to use Docker containers
  • Basics
    • ▶️Pull and run an image
      • Trivia
    • Basic docker commands
    • Container life cycle
  • Build an Image
    • ▶️Console app experiment
      • Hello-world image
    • What is a docker file?
      • Our docker file explained
    • ▶️Web app experiment
      • Create application
      • Create a docker file
      • Build an image
      • Run your image
      • Manipulating containers
  • Layers & Stages
    • Introduction
    • Image layers
    • Multistage images
Powered by GitBook
On this page
  1. Basics

Container life cycle

PreviousBasic docker commandsNextConsole app experiment

Last updated 1 year ago

Docker container life cycle

To place a container in the run state, use the run command. You can also restart a container that is already running. When restarting a container, the container receives a termination signal to enable any running processes to shut down gracefully before the container's kernel is terminated.

A container is considered in a running state until it's either paused, stopped, or killed. A container, however, may also exit from the run state by itself. A container can self-exit when the running process completes, or if the process goes into a fault state.

To pause a running container, use the pause command. This command suspends all processes in the container.

To stop a running container, use the stop command. The stop command enables the working process to shut down gracefully by sending it a termination signal. The container's kernel terminates after the process shuts down.

To send a kill signal if you need to terminate the container, use the kill command. The running process doesn't capture the kill signal, only the container's kernel. This command will forcefully terminate the working process in the container.

Lastly, to remove containers that are in a stopped state, use the remove command. After removing a container, all data stored in the container gets destroyed.