## 1.查看image
[root@VM_0_9_centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
anaconda3 v2 69fbd3d374ef 6 days ago 2.74 GB
anaconda3 v1 5f7b8a1f9a53 7 days ago 2.74 GB
docker.io/continuumio/anaconda3 latest bdb4a7e92a49 9 days ago 2.7 GB
docker.io/centos latest 470671670cac 2 months ago 237 MB
docker.io/centos 7 5e35e350aded 4 months ago 203 MB
## 2. 启动容器
[root@VM_0_9_centos ~]# docker run -dit --name centos7 docker.io/centos:7
f03ad3e5b9853b06160fc9d602063c6adc27172f186f516b7ea2000cb9db1f54
[root@VM_0_9_centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f03ad3e5b985 docker.io/centos:7 "/bin/bash" 16 seconds ago Up 16 seconds centos7
## 3. 进入容器后,做一些修改
[root@VM_0_9_centos ~]# docker exec -it centos7 bash
## 4. 将容器centos7保存为centos:latest镜像
[root@VM_0_9_centos ~]# docker commit -a 'kwq' -m 'make some change' centos7 centos7:latest
sha256:952de7d78abf1ef54206c18ea86f62998bf749724fd65655f5cc278106c9e894
[root@VM_0_9_centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7 latest 952de7d78abf 4 seconds ago 203 MB
anaconda3 v2 69fbd3d374ef 7 days ago 2.74 GB
anaconda3 v1 5f7b8a1f9a53 7 days ago 2.74 GB
docker.io/continuumio/anaconda3 latest bdb4a7e92a49 9 days ago 2.7 GB
docker.io/centos latest 470671670cac 2 months ago 237 MB
docker.io/centos 7 5e35e350aded 4 months ago 203 MB
## 5. 将原centos7的容器停止、删除
[root@VM_0_9_centos ~]# docker stop centos7
centos7
[root@VM_0_9_centos ~]# docker rm centos7
centos7
## 6. 启动centos7:latest镜像
[root@VM_0_9_centos ~]# docker run -dit --name centos7 centos7:latest
53e1009d63027a25291c5b9a5cc84332cb4ac7012f5cd221ccb9a83d81333c67
## 7. 查看容器中的更改是否丢失
[root@VM_0_9_centos ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
53e1009d6302 centos7:latest "/bin/bash" 7 seconds ago Up 6 seconds centos7
[root@VM_0_9_centos ~]# docker exec -it centos7 bash
## 8. 保存镜像为tar包
[root@VM_0_9_centos ~]# docker save -o centos7.tar docker.io/centos:latest