Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Docker commit Command

Docker commit Command

Docker Command ReferenceDocker Command Reference


docker commit The commit command is used to save the current state of a container as a new Docker image.

docker commit The command is commonly used to create an image that preserves the state of a container so that the image can be reused or distributed later.

Syntax

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

OPTIONS description:

Save a container as a new image:


docker commit my_container my_new_image

Save the container named my_container as a new image named my_new_image.

Specify a tag:


docker commit my_container my_new_image:latest

Save the container as an image with the latest tag.

Add author and commit information:


docker commit -a "John Doe" -m "Added new features" my_container my_new_image

Save the container as a new image and add author and commit information.

Commit an image without pausing the container:


docker commit --pause=false my_container my_new_image

Save the container as a new image without pausing it.

Example

Start a container:


docker run -d -it --name my_container ubuntu bash

Make some changes:


docker exec my_container apt-get update
docker exec my_container apt-get install -y nginx

Commit the container as a new image:


docker commit -a "Your Name" -m "Installed nginx" my_container my_new_image

View the new image:


docker images

Common Scenarios

docker commit The commit command is a powerful tool that lets users save the current state of a container as a new Docker image. With this command, users can create custom images for reuse or distribution later. Adding appropriate author and commit information helps track the history and changes of an image.


Docker Command ReferenceDocker Command Reference