Docker commit command
docker commitThe command is used to save the current state of a container as a new Docker image.
docker commitThe command is typically used to create an image to save the state of a container, so that the image can be reused or distributed in the future.
Syntax
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
OPTIONS description:
-a :The author of the committed image.
-c :Use Dockerfile instructions to create an image.
-m :The commit message.
-p :Pause the container before committing the image (default is true).
Save the 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 tag:
docker commit my_container my_new_image:latest
Save the container as an image tagged with latest.
Add author information and commit message:
docker commit -a "John Doe" -m "Added new features" my_container my_new_image
Save the container as a new image, adding author information and commit information.
Commit the image without pausing the container:
docker commit --pause=false my_container my_new_image
Save it as a new image without pausing the container.
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
- Save your work progress: During development or testing, save the current state of the container as an image so that it can be restored later.
- Create a base image: Create a custom base image for a specific application or environment configuration.
- Distribution configuration: Save a specific configuration or application state as an image for distribution to other team members or use in different environments.
docker commitThe command is a powerful tool that allows users to save the current state of a container as a new Docker image. By using this command, users can create custom images for future reuse or distribution. Adding appropriate author and commit information helps track the history and changes of the image.
other extensions