Docker

States of a Docker Container | Explained

Docker is a containerized forum that permits users to create, test, and execute applications. Docker containers are the important components of Docker. More specifically, a Docker container is a portable, executable software package that has all everything needed to execute an application. Docker utilizes a client-server architecture that allows communication between the Docker client and the Docker daemon, which creates and manages containers.

This article will describe the different possible states of the Docker container.

What are the States of a Docker Container?

The possible states of the Docker container are as follows:

Created State

When the new container is built or created, it enters in the “created” state. The “created” state refers to a container that has been created/built but is not in the running state. It means that the container exists on the device but it is not active now.

Command

The command for creating a Docker container is given-below:

docker create --name <container-name> <image-name>

Running State

The “running” state indicates that the container is currently executing without any issues. The “docker ps” command is used to check the running state of the container.

Command

To run the Docker container, utilize the “docker start” command along with the particular container name:

docker start <container-name>

Restarting State

The “restarting” state refers to stopping the container and starting again. It resets the container’s current state.

Command

Use the “git restart” command along with the desired container name that needs to be restarted:

docker restart <container-name>

Paused State

The “paused” state indicates that the container is temporarily stopped and is in the frozen state. It permits users to stop the execution of the container without actually stopping it so that its operations can be resumed from where they left off.

Command

To pause the particular container, run the below-listed command:

docker pause <container-name>

Exited State

The “exited” state of a container refers to the state of the container when it has stopped running. When the container finishes its task, it stops automatically and enters the “exited” state. Users can also stop the container manually using the command.

Command

Utilize the “docker stop” command with the particular container name to stop it:

docker stop <container-name>

Dead State

The “dead” state refers to the state when the container is no longer running and cannot be restarted. This can happen for various reasons, such as if the container has crashed or if it has been manually stopped and removed. A dead container is no longer running and cannot be started or restarted.

Conclusion

The possible states of a Docker container are created, running, restarting, paused, exited, and dead. The “created” state is the state when the container has been built but not active/started yet. The “running” state indicates that the container is currently executing. The “restarting” state refers to stopping the container and starting again. The “paused” state indicates that the container is temporarily stopped. The “exited” state of a container refers to the state of the container when it has stopped running. The “dead” state refers to the state when the container is no longer running and cannot be restarted.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.