Docker

What are the Steps to Restart a Docker Container that has been Stopped?

Docker containers have become increasingly important in modern software development and are commonly used in many software projects. They provide a consistent environment for the application to run. They are portable and provide isolation between the application and the local host machine. A Docker container can be in different states, such as “created”, “running”, “restarting”, “exited”, etc.

This blog will demonstrate the method to restart a Docker container that has been stopped.

What are the Steps to Restart a Docker Container that has been Stopped?

To restart a Docker container that has been stopped, the “docker start <container-name/ID>” command is used. To do so, follow the below-provided step-by-step instructions:

Step 1: View All Containers
First, display all the available containers and choose a particular container to stop it:

docker ps -a

In the above output, all the containers can be seen. We have selected the “myCont” container that is running.

Step 2: Stop Running Container
Then, stop the selected running container using the “docker stop” command along with the container name:

docker stop myCont

This command has stopped the “myCont” container.

Step 3: Verify Stopped Container
Next, use the provided command to ensure that the selected container has been stopped:

docker ps -a

The “myCont” container has been stopped successfully.

Step 4: Restart the Stopped Container
To restart the container that has been stopped, write out the “docker start” command along with the container name or ID:

docker start myCont

Alternatively, the user can also use the desired container ID to restart it:

docker start 5188a3a428d1

This command has restarted the stopped container.

Step 5: Verify Restarted Container
To verify whether the container has been restarted or not, execute the provided command:

docker ps -a

As you can see the “myCont” container has been restarted successfully.

Bonus Tip: Restart the Running Container
To stop the container and start it again, use the “docker restart <container-name/ID” command:

docker restart myCont

The above command has stopped the “myCont” container and started it again.

Conclusion

To restart a Docker container that has been stopped, the “docker start ” command is used. Users can also use the “docker restart <container-name/ID” command to stop the container and start it again. This blog has demonstrated the method to restart a Docker container that has been stopped.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.