This guide will explore what Docker Commit is and provide examples that can be used to create new Docker images, and when to use it.
What is Docker Commit?
The Docker commit command lets users create a new Docker image from the contents of a container. This new image includes the base image along with a layer that has the changes made inside the container.
It can be helpful to save a container’s file changes or settings as a new image. This allows you to debug a container using an interactive shell or transfer a functional dataset to another server.
Commits do not capture any data from mounted volumes.
By default, the container being committed and its processes will be paused during the image creation. This minimizes the risk of data corruption while making the commit. If you do not want this behavior, set the –pause option to false.
Syntax
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
- CONTAINER: Name or ID of Docker container.
- REPOSITORY: Name of the repository to which you want to push the Docker image.
- TAG: Tag the new image.
Options
Option | Default | Description |
---|---|---|
-a, --author | Author (e.g., John Hannibal Smith <[email protected]> ) | |
-c, --change | Apply Dockerfile instruction to the created image | |
-m, --message | Commit message | |
-p, --pause | true | Pause container during commit |
Docker Commit Examples
Here are some Docker Commit Examples you must learn:
Get exclusive access to all things tech-savvy, and be the first to receive
the latest updates directly in your inbox.
Commit a container
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c3f279d17e0a ubuntu:24.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
197387f1b436 ubuntu:24.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
docker commit c3f279d17e0a svendowideit/testimage:version3
f5283438590d
docker images
REPOSITORY TAG ID CREATED SIZE
svendowideit/testimage version3 f5283438590d 16 seconds ago 335.7 MB
Commit a container with new configurations (–change)
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c3f279d17e0a ubuntu:24.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
197387f1b436 ubuntu:24.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
docker inspect -f "{{ .Config.Env }}" c3f279d17e0a
[HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin]
docker commit --change "ENV DEBUG=true" c3f279d17e0a svendowideit/testimage:version3
f5283438590d
docker inspect -f "{{ .Config.Env }}" f5283438590d
[HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin DEBUG=true]
Commit a container with new CMD
and EXPOSE
instructions
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c3f279d17e0a ubuntu:24.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
197387f1b436 ubuntu:24.04 /bin/bash 7 days ago Up 25 hours focused_hamilton
docker commit --change='CMD ["apachectl", "-DFOREGROUND"]' -c "EXPOSE 80" c3f279d17e0a svendowideit/testimage:version4
f5283438590d
docker run -d svendowideit/testimage:version4
89373736e2e7f00bc149bd783073ac43d0507da250e999f3f1036e0db60817c0
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89373736e2e7 testimage:version4 "apachectl -DFOREGROU" 3 seconds ago Up 2 seconds 80/tcp distracted_fermat
c3f279d17e0a ubuntu:24.04 /bin/bash 7 days ago Up 25 hours desperate_dubinsky
197387f1b436 ubuntu:24.04 /bin/bash 7 days ago
Commit with changes Applied
docker commit --change="ENV DEBUG=true" <container_id> <new_image_name>
Commit with Author Information
docker commit -a "Author Name" <container_id> <new_image_name>
Step-by-Step: Using Docker Commit
Commit a Container
Step 1: Pull a Docker Image
The first step is to pull the image as illustrated in the image below. Use the command to pull the image into your system, as shown below.
docker pull alex43/ubuntu-with-git:v1.0<br>docker pull
Step 2: Deploy The Container
After pulling the image, run the container using the command below. The “-it” flag tells Docker to create an interactive bash shell in the container by linking a pseudo-TTY to the container’s stdin. This command opens a new container and takes you to a fresh shell prompt so you can start working inside it.
docker run -it bin/bash<br>docker run
Step 3: Modify The Container
Now that we are in the container, we can install the necessary package or modify the image. Here, we will try to install Nmap Software. Before installing, check if the software is already installed with the following command.
nmap --version
To install Nmap, use the command below.
apt-get install nmap
Running a container
Once the installation is done, confirm again that the software was installed as shown in the example below. Then exit from the container.
Version
Step 4: Commit Changes to The Image
Finally, commit the changes using the syntax below to create a new image. Use the container ID and tag the new image with a new tag.
sudo docker commit [CONTAINER_ID] [new_image_name]
Docker Commit vs. Dockerfile: Which Should You Use?
Aspect | Docker Commit | Dockerfile |
---|---|---|
What it does | Saves a container’s state as an image | Defines steps to build an image |
Use Case | Quick snapshot, one-off changes | Reproducible, automated builds |
Reproducibility | Low (manual, hard to track) | High (scripted, version-controlled) |
Best For | Prototyping & experiments | Production & CI/CD pipelines |
Ease | Simple but less maintainable | Requires setup, highly maintainable |
When To Use Docker Commit Container
The commit Docker Container comand creates a new image from an existing container, capturing any modifications like added packages or file changes.
There are two main reasons to use docker commit
for creating new image versions:

- Generating image templates. For example, if you always use a specific set of tools on Ubuntu, you can run an Ubuntu container, install the tools, and commit the changes to create a template image for future use.
- Creating quick application iterations. For example, when testing an application, you can make fixes and tweaks inside a container and then commit them to an image for sharing with a team or performing further testing.
Summary!
We’ve explored Docker Commit in detail, which’ll help you run your containers as images.
It enables you to swiftly save the state of a running container as an image, but it does not offer reproducibility or version control, making it ideal for experiments, debugging, or temporary snapshots.
I’ve also mentioned the Docker Commit container and Dockerfile differences in a table; both methods are for generating Docker Images.
Conversely, Dockerfiles offer a systematic, repeatable, and automated approach to image creation. They are version-controlled, clear, and designed for production settings and CI/CD processes.
FAQ’s
What does Docker commit do?
Docker Commit container captures a snapshot of the current state of a running (or stopped) container and generates a new image based on those modifications.
Are changes in volumes included when you run docker commit?
No, changes made in mounted volumes are not included in the Docker commit. Only the filesystem of the container (excluding volumes) is taken into account.
Does Docker commit pause the container while creating the image?
Yes, by default, the container is paused during the commit process to prevent data corruption, but you can use the –pause=false option if you want to avoid pausing.
How do I include new configurations or commands when using Docker commit?
You can use the –change or -c flag with docker commit to implement changes similar to those in Dockerfile instructions (like CMD, ENV, EXPOSE, etc.).
When should I not use Docker commit and instead use a Dockerfile?
For production scenarios or when you need reproducibility, version control, collaboration, and automated builds to be prioritized.
Does docker commit
include environment variables, CMD, or ENTRYPOINT from the container?
By default, docker commit
preserves the container’s environment variables, CMD, and ENTRYPOINT settings. However, you can override or add instructions using the --change
(-c
) flag, for example:
docker commit -c 'CMD ["nginx", "-g", "daemon off;"]' <container_id> myimage:latest
.