Lifecycle Management for Docker Containers: Create, Run, Pause, Stop, and Delete

0 / 123
Docker lifecycle management

Overview of docker lifecycle

  Containers are essentially instances of Docker images that may be executed using the Docker run command. Docker’s primary goal, on the other hand, is to execute containers. We may use the Docker API or CLI to create, launch, stop, move, or destroy containers. Furthermore, we may link a container to one or more networks, attach storage to it, or even construct a new image based on its existing state. The Docker Container Lifecycle describes the many processes involved in the creation of a Docker container. Some of the states are: Created – A container that has been created but has not yet been started. Running – A container that is actively running all of its processes. Paused – A container whose processes have been paused. Stopped -A container whose processes have been halted. Deleted – A container that is no longer useful. What happens when we execute docker commands? The Docker create command generates a new container based on the image given. However, the container will not be started right away.
Create docker

docker create

  To restart any halted container, use the Docker start command. If we used docker to construct a command, we can start it using this command.
Docker start

docker start

  Docker run is a mix of create and start since it both creates and starts a new container. In fact, if the specified image is not found on your machine, the docker run command can even get it from Docker Hub.
Docker run

docker run

  The docker pause command suspends all processes in the specified containers. Traditionally, when suspending a process, the SIGSTOP signal is used, which is visible to the process being suspended. Also, the memory part would be there when the container is paused, and it would be utilised again when the container is restarted.
Docker pause

docker pause

  When we execute the docker stop command, the primary process within the container receives SIGTERM and, after some time, SIGKILL signals. It will also release the RAM utilised once the container has been halted.
Docker stop

docker stop

  Using docker rm we may delete one or more containers from the host node, and we can use the container name or ID to do so.
Docker remove

docker remove

  docker kill sends SIGKILL or any signal given with the –signal option to the main process within each container specified.
Docker kill

docker kill

  Docker Container Lifecycle Management Overview with commands – Docker Container Lifecycle Management refers to the process of managing the states of Docker containers. We must ensure that the containers are operational, or that they be destroyed if they are no longer useful. We have several typical commands for controlling the Docker Lifecycle, which are detailed more below. Create Containers Using the docker create command, a new Docker container with the supplied docker image is created.
1
# docker ps
1
# docker create --name nginx-app nginx 
1
# docker ps
image1 Start Container The docker start command can be used to restart a previously halted container.
1
docker ps
1
docker ps -a
1
docker start b4dcd6331e0c
1
docker ps
1
docker ps -a
image2 Run Container The docker run command performs the functions of both the “docker create” and “docker start” commands. This command will build a new container and execute the image within it.
1
docker ps
1
docker images
1
docker run -it --name nginx-app-v1 -d -p 8080:80 nginx
1
docker ps
image3 Pause Container We may use the “docker pause” command to pause the processes operating within the container.
1
docker ps
1
docker pause nginx-app-v1
1
docker ps
1
docker unpause nginx-app-v1
1
docker ps
image4 Stop Container When you terminate a running Container, you also stop all of the processes that are executing in that Container. Stopping does not imply killing or putting a stop to the process.
1
docker ps -a
1
docker stop
1
dokcer ps -a
image5 Delete Container Removing or removing the container entails first terminating all processes operating inside the container and then deleting the Container. It is preferable to destroy the container only if it is in the halted condition rather than violently terminating the operating container.
1
docker ps
1
docker ps -a
1
docker rm nginx-app-v1
1
docker rm nginx-app
1
docker ps -a
1
docker ps 
We have to first stop the container and delete it. image6 Kill Container We can terminate one or more running containers.
1
docker ps
1
docker ps -a
1
docker run -d -it --name nginx-app-v1 -p 8080:80 nginx
If the container is not running then run it using above command.
1
docker kill nginx-app-v1
1
docker ps
1
docker ps -a
image7 I hope you now have the knowledge you need to learn more about docker containers lifecycle and perhaps utilise them in a project in the future.   Follow us on facebook:- Facebook  & Linkedin:- LinkedIn  

Comments

comments


***Linux, Cloud & Devops Architect & Technical Content Writer*** I am a Linux Enthusiast and Supporter/Promoter of Open Source Technology with over 12+ years of experience in Linux, Cloud and Devops. I am A Technical Content writer for various sites like : Hostbread & Golibrary

Related Posts