Reputation: 587
I have one docker image which spins up a container for executing some task in a small time period. Container is exited as soon as the task is completed.
Below is the output from docker ps -a
command
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
40be32cb4299 88841cd3d4a7 "/home/test/testing-…" 40 seconds ago Exited (0) 22 seconds ago beautiful_agnesi
Since the container is automatically exited in small time period, I can't perform docker exec -it -u root 40be32cb4299 bash
Output of exec command gives below error since container is exited.
Error response from daemon: Container 40be32cb4299 is not running
Is there way for me to perform exec on this container for editing some files inside the same container in order to perform docker commit
and save as new image ?
Upvotes: 1
Views: 2463
Reputation: 3
You can start a stopped container. To make this simple name your container
docker run --name container_name image_name
Start the container using the container name
docker start container_name
Now exec the rest of the commands
docker exec $(docker start container_name) //bin/bash -c " your command"
Just remember to run the container without --rm
Upvotes: 0
Reputation: 31584
There is no way to exec into a stop container. But, you really have workaround to achieve you aim, something like next:
docker commit 40be32cb4299 old_image
, this commit the old stopped container as an old docker image.docker run -it --entrypoint=/bin/bash --name=new_container old_image
, this use the old image to start a new container. As the entrypoint
has been override, so the new_container
will not run your default entrypoint
or command
, then new_container
won't exit, and with -it
, you are now in the new container.docker commit new_container new_image
to commit your new changes to a new docker image.Upvotes: 2