How to Run Commands in a Stopped Container
- Last Updated On: March 2, 2019
- By: Scriptcrunch Editorial
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,
- 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.
- 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.
docker commit (stopped container name/id) (user defined image name)
For example,
docker commit 8bd2a352dd5a michael/apache
2. Now, run the image in interactive mode using the new committed image name as shown below.
docker run -it (image name) (command)
For example,
docker run -it michael/apache /bin/sh
That’s it. Now you will have a terminal session to your container and you can run commands against it.
Scriptcrunch Editorial
Other Interesting Blogs
[50% OFF] Kubernetes Certification Coupons (CKA, CKAD, CKS, KCNA and KCSA)
Looking for CKA coupon and other Kubernetes certification coupon codes? You have come to the right place. Following are the list of
[80% OFF] Linux Foundation Coupon for December 2024
Looking for CKA Coupon and other Linux Foundation certifications coupons? We got you covered. With the latest Linux Foundation Coupon, you can
[65% OFF] Linux Foundation LFCA, LFCS & LFCT Exam Voucher Codes
Linux Foundation has announced up to a $284 discount on its Linux certification programs Linux Foundation Certified IT Associate (LFCA) and Linux