How To Stop One Docker Container At A Time
Follow the below steps to stop one Docker running container at a time.
Step 1: Start The Docker Service
- Open your command line containing the Docker software and start The Docker Service with following command:
systemctl enable docker --now
Step 2: Run A Docker Container
- Start The Container using docker run, for example take this as a command:
docker run -dit --name mycontainer centos:latest
Step 3: List The Running Containers
- Run the following command to view the running containers:
docker ps
- To know and view all the containers either they are running or get terminated specify the above command with option -a , the command looks as given below:
docker ps -a
Step 4: Stop The Docker Container
- If multiple containers are running then the specific container name or ID that you are looking to stop. In this case I want to stop the container with name mycontainer.
docker stop mycontainer
- In this, the docker container with name my_container is get stopped from the execution, by sending the SIGTERM signal to backend through the option stop and finally the my_container leads to the graceful termination. This below shows you that clearly.
Step 5: Stop The Docker Container With Time Period ( Optional )
- You can also stop a running docker container with a grace period of 30 seconds and exits.
docker stop --time=30 myc1
Docker Stop Command |A Complete Tutorial:Defnition,Syntax,Examples
In the field of Docker container management, the docker stop command serves as a critical tool for mainly shut-down containers. This article talks about the working of the docker stop command, explaining its purpose, usage, and importance of proper container termination.