Docker is well known for its containerized concept. The Docker containers are an essential part of the Docker platform that is utilized for building, deploying, and shipping applications. These containers pack the program dependencies and source code. While working with the Docker containers, developers are usually required to start and stop the Docker container. For this purpose, Docker containers are supported by various commands to provide different functionalities.
This blog will demonstrate how to stop Docker containers in Docker.
How to Stop Docker Containers?
While managing applications on Docker, users must create, start and stop Docker containers. For doing so, go through the provided instructions.
Step 1: Create Docker Container
First, create a Docker container with the help of a Docker image. To do so, check out the mentioned command. Here:
- “-i” flag creates the container in an interactive way.
- “-p” defines the port to execute the container.
- “–name” flag is utilized to define the name of the container.
- “dockerimage” is a Docker image used to create a Docker container:
Step 2: Start Docker Container
Next, start the container to execute it on a specified port using the “docker start” command:
Next, navigate to the “localhost:<specified-port>” and check if the container is running or not. From the below output, you can see that we have successfully executed the container on port “8080”:
Step 3: Stop Docker Container
In order to stop the container in Docker, utilize the “docker stop container-name” command. However, users can also use container id instead of container name:
Container id can be viewed by listing all Docker containers:
Step 4: Stop All Containers in Docker
To stop all executing containers, go through the below-mentioned command. Here, “-a” is used to select all containers, and “-q” is utilized to display only container ids:
This is all about how to stop the Docker containers in Docker.
To stop the running container of Docker, utilize the “docker stop <container-name>” command. Users can use container id as well to stop the container. In order to stop all running containers in Docker, utilize the “docker stop $(docker ps -a -q)” command. This blog has demonstrated how to stop the Docker containers in Docker.