How to Run Commands in a Stopped Container

There are few situations in which you might want to get into the container shell or may be run a single command in a stopped container.

Situations like,

  1. You started building an image and it stopped at some point. You are only left with an intermediate container and you want to troubleshoot it.
  2. The image you built is not starting up and you want to into the containers shell for troubleshooting.

In this guide, you will learn how to run commands against a stopped docker container.

Run Commands in a Stopped Container

Ther is no way you can run commands in a stopped container as the container needs to be in running state for getting the  shell access or for executing commands.

For both scenarios explained above, there is one solution. You need to commit the stopped container to an image and then run a container in interactive mode to gain access to the shell or terminal.

Follow the instructions given below.Commit the image of the stopped container using the command syntax shown below.

1 . Commit the image of the stopped container using the command syntax shown below.

For example,

2.  Now, run the image in interactive mode using the new committed image name as shown below.

For example,

That’s it. Now you will have a terminal session to your container and you can run commands against it.


docker remote api

You will need Docker remote API in various situations. Let's say you are running the docker host on a remote server…

Read more
docker cheat sheet - beginners guide

Docker has many commands to remember. If you are starting up with docker, We are pretty sure that you will have a hard…

Read more

The Best Tutorials & Tips to Speedup Your DevOps Workflow.

Created by Bibin Wilson.