Docker:Commit
lastmod 2025-05-20created 2020-04-075 edits
docker commit: a command that even revives stopped containers
The docker exec command has one critical problem: you can only access the container environment while the container is running. Unfortunately, for system administrators, performing an autopsy on the state of a dead container is more important than exploring the runtime environment of a live one. And a container that died from an internal problem often dies again right away even when re-run with restart. So for dead containers, the exec command is useless.
In such cases, one option to consider is docker commit. commit is a command that turns a specific state of a container into an image as-is. This command is used during the Docker build process, but you will rarely need to use it directly. For more on how image builds work and on commit, see the following post.
Understanding Docker images by building them: how Docker image builds work and OverlayFS
Options
-
--change - The
--changeoption will apply Dockerfile instructions to the image that is created. - Supported Dockerfile instructions -
CMD|ENTRYPOINT|ENV|EXPOSE|LABEL|ONBUILD|USER|VOLUME|WORKDIR
How to create a hotfix image from a stopped container
Change the entrypoint to bash as follows, then debug and fix:
If you need administrator privileges, log in as the root user:
After finishing the fix with vi or similar, quit with exit.
Check the container state with the command using the -l flag (last created container):
It will probably be in the "Existed" state.
Do not commit right away. If you check the Entrypoint of the container you just ran with the inspect command, you can see it has changed to bash.
The output will probably look like this:
When committing, restore the original ENTRYPOINT that goes in the Dockerfile with the --change option.
If you logged in as root, the user may have changed. Check the user of the original image: (look at the Config > User field)
docker commit --change='USER app' --change='ENTRYPOINT ["python", "-OO", "-m", "ddrm"]' ddrm-hotfix ddrm:0.0.9-hotfix
Check the created image:
Check the Entrypoint of the created image:
The output will probably look like this:
The container created for the hotfix still exists.
Remove it if necessary:
If in doubt, check the changes inside the newly created image: