docker commit
docker commit
Creates an image from a container. Useful occasionally, but docker build is usually better because it is reproducible. Containers are paused before commit by default; pass --pause=false to skip that. Use -a and -m for author and comment metadata.
Example:
ID=$(docker run -d redis touch /new-file)
docker commit -a "Joe Bloggs" -m "Comment" $ID commit:test
docker images commit
docker run commit:test ls /new-file
Hands-on example
Start a container and install software:
docker run -it --name cowsay --hostname cowsay debian bash
Inside the container:
apt-get install -y cowsay fortune
/usr/games/fortune | /usr/games/cowsay
exit
Commit it as an image:
docker commit cowsay test/cowsayimage
Pass the container name (
cowsay), image name (cowsayimage), and repository (test).
The command returns the new image ID.
Result
Run the image anytime:
docker run test/cowsayimage /usr/games/cowsay "Moo"
Related topics
- Creating images — Dockerfile workflow
- Export and import — alternative ways to move filesystems
Andrew Dorokhov