[Self-study Docker] Docker commit command

Docker commit command

outline

insert image description here

docker commit command tutorial

The docker commit command is used to create a new Docker image based on the changes made to the Docker container . The CONTAINER after this command can be the container ID or the container name.

docker commit command syntax

haicoder(www.haicoder.net)# docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

docker commit command parameters

parameter describe
-a, --author string author.
-c, --change list Apply the dockerfile instructions to create the image.
-m, --message string Submit Information.
-p, --pause Pause the container during commit (default true).

the case

Commit container changes

Use the docker run -it command to run a dokcer container.

haicoder(www.haicoder.net)# docker run -it --name haicoder centos
[root@602cac714951 /]# 

At this point, the terminal command line becomes the form of the container id, that is, we have entered the inside of the container. Run the vim command inside the container, it prompts that there is no such command, and the terminal prompts as shown in the following figure:

Please add a picture description

We use yum to install vim command:

[root@602cac714951 /]# yum install -y vim

The terminal displays the following figure, which means the installation is successful:
insert image description here

After the installation is complete, we can use the vim command inside the docker container.

[root@602cac714951 /]# whereis vim
vim: /usr/bin/vim /usr/share/vim

For convenience, we use the docker commit command to submit the docker container that has installed the vim command for subsequent use.

haicoder(www.haicoder.net)# docker commit haicoder centos-vim
sha256:1dfd8a9f5ccf89ca83e231211623f788873a715cce7eb284c57bb9cdefe5f0ae

We use the docker images command to view the submitted docker image, and the terminal displays the following figure:

insert image description here

We now run a new container based on the docker image we just committed.

haicoder(www.haicoder.net)# docker run -it --name haicoder-vim centos-vim
[root@58bfea027dcb /]# whereis vim
vim: /usr/bin/vim /usr/share/vim
[root@58bfea027dcb /]# 

After creation, we can directly use vimthe command. Use **docker kill** and docker rm commands to remove all containers.

haicoder(www.haicoder.net)# docker kill `docker ps -qa` ; docker rm `docker ps -aq`

Summary of docker commit command

The docker commit command is used to create a new Docker image based on the changes made to the Docker container.

Guess you like

Origin blog.csdn.net/weixin_41384860/article/details/128819642