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 ?
2
Answers
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 theentrypoint
has been override, so thenew_container
will not run your defaultentrypoint
orcommand
, thennew_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.You can start a stopped container. To make this simple name your container
Start the container using the container name
Now exec the rest of the commands
Just remember to run the container without –rm