arrow_back
Back

Creating a Docker image manually with docker commit

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

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"
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward