Linux Linux Commands

Docker Stop Container Commands [Examples]

Docker Stop Container Commands [Examples]
Written by itsubuntu

Docker Stop Container Commands Tutorial

In this tutorial post, we are going to show the docker commands to stop one or more running containers. We will learn about how to stop or kill the running docker containers.

Docker Stop Container Commands

Before stopping any container, you need to make sure if there is any docker command running or not with the following command. The docker ps command returns a list of all running containers.

sudo docker ps

Run the following command to list both running and stopped containers with the -a option as follows:

docker ps -a

Run the following command to list only the container ID with the -aq option.

docker ps -qa

Run the following command to run the container by the container ID.

sudo docker run 80259da11a6f

Run the following command to create the last container that you have created:

 docker ps -l

Starting A Docker Container [With Examples]

Docker Start Container Command Syntax:

ocker run [ OPTIONS ]  IMAGE[:TAG]  [COMMAND]  [ARG...]

Docker Start Container Command Example:

docker container run nginx

Stopping A Docker Container [With Examples]

Docker Stop Container Command Syntax:

docker stop [-t|--time[=10]] CONTAINER [CONTAINER...]

Docker Stop Container Command Example:

docker stop 80259da11a6f

How To Stop All Docker Container

Run the following command to stop all docker containers at once.

docker stop `docker ps -q`

How To Delete A Docker Container

Run the following command to delete a docker container.

docker rm [ OPTIONS ] CONTAINER [ CONTAINER ]

First, you need to stop a container so that you can delete it:

docker stop 80259da11a6f

Example:

docker rm 80259da11a6f

Run the following command to delete all the containers at once. You need to run the command to stop them at once and then you can delete them.

docker stop `docker ps -q`
docker rm `docker ps -aq`

How To Stop A Docker Container After Certain Time Interval

Run the following command to stop a docker container after a certain time.

docker stop --time=30 container_id

About the author

itsubuntu

Leave a Comment