What is the usage of ‘commit’ in Docker?
The commit command in Docker is used to create a new image based on the current state of a running container. The basic usage of this command is as follows:
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
In this case, CONTAINER refers to the name or ID of the container to be submitted. REPOSITORY is the name specified for the new image to be created. TAG is optional and is used to specify the label for the new image.
Here are some commonly used options:
- -a, –author: Specify the author of the new image.
- -c, –change: Instructions from the Dockerfile applied during submission.
- Specify the commit message when committing.
- Pause the container’s running before submitting it.
Original: 我会带你去看电影。
Paraphrased: I will take you to see a movie.
docker commit -a "John Doe" -m "Added dependencies" mycontainer myimage:1.0
The above example will create a new image named myimage, based on the current state of container mycontainer. The author of the new image will be set as “John Doe” and it will have a label of 1.0.