Lifecycle Management for Docker Containers: Create, Run, Pause, Stop, and Delete
0
/
123
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. 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 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. 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. 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. 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 kill sends SIGKILL or any signal given with the –signal option to the main process within each container specified. 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 |
1 | docker ps |
1 | docker ps -a |
1 | docker start b4dcd6331e0c |
1 | docker ps |
1 | docker ps -a |
1 | docker ps |
1 | docker images |
1 | docker run -it --name nginx-app-v1 -d -p 8080:80 nginx |
1 | docker ps |
1 | docker ps |
1 | docker pause nginx-app-v1 |
1 | docker ps |
1 | docker unpause nginx-app-v1 |
1 | docker ps |
1 | docker ps -a |
1 | docker stop |
1 | dokcer ps -a |
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 |
1 | docker ps |
1 | docker ps -a |
1 | docker run -d -it --name nginx-app-v1 -p 8080:80 nginx |
1 | docker kill nginx-app-v1 |
1 | docker ps |
1 | docker ps -a |