Tutorial 3: Starting and Stopping the Docker Containers

Gaurav Patil
4 min readSep 11, 2022
Photo by Rubaitul Azad on Unsplash

Missed previous tutorial ? : click here.

We will cover following topics in this tutorial:

Pulling the images from Docker Hub

Stopping the container

Starting the container

Pulling the images from Docker Hub :

docker pull hello-worlddocker run hello-world

Output :

The message “Hello from Docker” confirms that hello-world image is running successfully.

Let’s try to pull another Docker image from Docker Hub.

docker pull redis

Output :

This Docker image is running, so it shows the status “ready to accept connections”, press ‘Ctrl + c’ to exit.

Following command will show all the containers which are up(running).

docker ps 

Output :

Check the ‘Status’ in the output which says ‘Up 2 minutes’ meaning container is up(running) since 2 minutes. This confirms that ‘redis’ container is running.

Following command will enlist all the running and exited containers.

docker ps -a 

Output :

Check status of both the containers in the output, ‘hello-world’ exited while ‘redis’ container is still running.

We can stop the running container as given below.

Stopping the container :

Stopping the container command needs the container ID which can be obtained from the output of “docker ps”.

docker stop <1container_ID> <2container_ID> <3container_ID> ...

For stopping multiple containers, you can write multiple container IDs separated by space.

Run following command to stop the container :

docker stop b93f7f625300

Output :

Let’s check if the container is still running :

docker ps 

Output :

Empty output shows that running container is stopped now.

So logically the stopped container should have been exited, let’s check it’s status by running following command :

docker ps -a 

Output :

See both containers status is Exited meaning both are stopped. So it worked !!

Stopping the container does not delete the respective images.

Check by running following container :

docker images

Output :

Starting the container :

Starting the container command needs the container ID which can be obtained from the output of “docker ps -a”.

docker start <1container_ID> <2container_ID> <3container_ID>

For starting multiple containers, you can write multiple container IDs separated by space.

Run following command :

docker start b93f7f625300

Output :

This command will “up” (start)the container.

Let’s check if the container is up (running) :

docker ps

Output :

In above output, status ‘Up for 3 minutes” confirms that container is running.

So we have learnt to start and stop the container. Just make sure to stop the container otherwise it will keep running in the background.

docker stop b93f7f625300

You can run docker ps just to make sure that container is stopped.

Congratulations !!

Till now we performed all the operations on the image of the Docker Hub. We are yet to create our own Docker image that will be unfolded in our upcoming tutorial.

Take a deep breath and move to the next tutorial.

--

--

Gaurav Patil

Machine Learning Engineer drawing insights from mathematics.