Environment: Fedora release 32 (Thirty Two)
Method 1: Use the export command to export, and then create a new image.
After modifying the system configuration, check the current container name or id, and execute the following command to generate a new image.
[root@Centos7 ~]# docker export 120f93e71bb1 > myfedora.tar
[root@Centos7 ~]# cat myfedora.tar |docker import - mynewfedora:latest
sha256:349fbf8ea74700ce6fd0cc3f903ddcae7626cc5e3aeb9f89d415985fca6d8127
[root@Centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynewfedora latest 349fbf8ea747 8 seconds ago 403MB
Method 2: Use the commit command to generate a new container image.
[root@Centos7 ~]# docker commit 120f93e71bb1 mynewfedora2
sha256:68ea6f3e4e0b8d0abedaba056d27944687d7cae842850111dffe3bddf908dba3
[root@Centos7 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mynewfedora2 latest 68ea6f3e4e0b 7 seconds ago 414MB
mynewfedora latest 349fbf8ea747 3 minutes ago 403MB
TIPS : When running the container through the image created by the first method, there is an error as follows:
[root@Centos7 ~]# docker run -it mynewfedora
docker: Error response from daemon: No command specified.
See 'docker run --help'.
By comparing another image just now mynewfedora2 or the fedora image on the official website, it is found that in the image generated by this method, the parameter in Cmd is null, and the /bin/bash parameter of other images is missing:
[root@Centos7 ~]# docker inspect mynewfedora|grep -A 5 Cmd
"Cmd": null,
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
--
"Cmd": null,
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
Compared:
[root@Centos7 ~]# docker inspect mynewfedora2|grep -A 5 Cmd
"Cmd": [
"/bin/bash"
],
"ArgsEscaped": true,
"Image": "fedora",
"Volumes": null,
--
"Cmd": [
"/bin/bash"
],
"ArgsEscaped": true,
"Image": "fedora",
"Volumes": null,
So when running the container with this image, you need to add /bin/bash to the command:
[root@Centos7 ~]# docker run -it mynewfedora /bin/bash
[root@515b2b933bb4 /]#
Reference document:
https://blog.csdn.net/shenghuiping2001/article/details/93378185