docker commit Explained

What docker commit does, with an example.

Published November 9, 2026

docker commit creates a new image from a container's current state. It is handy for quick experiments but is not a repeatable way to build images.

How it works

Changes made inside a container (installed packages, edited files) are captured as a new layer.

Prefer a Dockerfile so builds are documented and reproducible.

Try it

docker commit web web-snapshot:1
sha256:9f8e7d6c...
docker images web-snapshot

Practical examples

Snapshot a container

docker commit web web-snapshot:1

With message and author

docker commit -m "added config" -a "Ada" web web:v2

Run the snapshot

docker run -it web-snapshot:1 bash

Better: Dockerfile

FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf

Common mistakes

  • Using commit as the build process (not reproducible).
  • Committing secrets and large caches.
  • Losing track of what changed.

Key takeaways

  • docker commit creates a new image from a container's current state.
  • Run docker <command> --help for all options.
  • Clean up unused resources regularly.

FAQ

Commit vs build?

Build is repeatable from a Dockerfile; commit captures ad-hoc state.

Where can I see all options?

Run the command with --help.

More General articles