docker学习记录:commit,制作自己的镜像
1.清除所有
kt@kt-SYS-4028GR-TR2:~$ sudo docker rm -f $(sudo docker ps -aq)
2.再操作一次tomcat,修改好,再打成一外镜像
kt@kt-SYS-4028GR-TR2:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 9.0 39642322f89a 3 weeks ago 469MB
tomcat latest f62f518e5c5c 3 weeks ago 467MB
mongo latest f08e39122805 4 weeks ago 855MB
kibana 7.17.26 86125e209614 4 weeks ago 866MB
nginx latest f876bfc1cc63 5 weeks ago 192MB
centos latest 5d0da3dc9764 3 years ago 231MB
elasticsearch 6.4.0 1ac676545731 6 years ago 791MB
kt@kt-SYS-4028GR-TR2:~$ sudo docker run -it --name mytomcat -p 8080:8080 tomcat:9.0
3.修改记录
root@d05e50e4bcde:/usr/local/tomcat/webapps.dist# ls
docs examples host-manager manager ROOT
root@d05e50e4bcde:/usr/local/tomcat/webapps.dist# cp . ../webapps
cp: -r not specified; omitting directory '.'
root@d05e50e4bcde:/usr/local/tomcat/webapps.dist# cp -r . ../webapps
root@d05e50e4bcde:/usr/local/tomcat/webapps.dist# ls
docs examples host-manager manager ROOT
root@d05e50e4bcde:/usr/local/tomcat/webapps.dist# cd ../webapps
root@d05e50e4bcde:/usr/local/tomcat/webapps# ls
docs examples host-manager manager ROOT
root@d05e50e4bcde:/usr/local/tomcat/webapps# cd ..
root@d05e50e4bcde:/usr/local/tomcat# cp -r ./webapps.dist/* ./webapps/
4.结果
5.生成修改后的镜像,然后查看。
kt@kt-SYS-4028GR-TR2:~$ sudo docker ps -a
[sudo] password for kt:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d05e50e4bcde tomcat:9.0 "catalina.sh run" 40 minutes ago Up 40 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp mytomcat
kt@kt-SYS-4028GR-TR2:~$ docker commit --help
Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Create a new image from a container's changes
Aliases:
docker container commit, docker commit
Options:
-a, --author string Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
-c, --change list Apply Dockerfile instruction to the created image
-m, --message string Commit message
-p, --pause Pause container during commit (default true)
kt@kt-SYS-4028GR-TR2:~$ sudo docker commit -a="duyicheng" -m="success" d05e50 mytomcat:1.0
sha256:bbdd452936a3063cd369cf12e685ca39df828dae830e44eba9c7bd1d4b418b54
kt@kt-SYS-4028GR-TR2:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mytomcat 1.0 bbdd452936a3 40 seconds ago 475MB
tomcat 9.0 39642322f89a 3 weeks ago 469MB
tomcat latest f62f518e5c5c 3 weeks ago 467MB
mongo latest f08e39122805 4 weeks ago 855MB
kibana 7.17.26 86125e209614 4 weeks ago 866MB
nginx latest f876bfc1cc63 5 weeks ago 192MB
centos latest 5d0da3dc9764 3 years ago 231MB
elasticsearch 6.4.0 1ac676545731 6 years ago 791MB
kt@kt-SYS-4028GR-TR2:~$
6.查看物理位置。
sudo docker inspect mytomcat:1.0
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/f800a777d89a26315ad30abc4397d29e9e3b1677f0395fa86569b264583a934c/diff:/var/lib/docker/overlay2/08f1074187cbe909153e9893fec1ee159580d4d13012136e47ea417fe6b3ab0d/diff:/var/lib/docker/overlay2/55d33ae1e59adc27089cbb89a7ed199017cccfb0d9ff137eff2a898cebe96245/diff:/var/lib/docker/overlay2/81b65dd56867a6f12ac898418665da498534a96c8908325d255a253de2b7ba05/diff:/var/lib/docker/overlay2/96ca15bd1eda45e81e83004abc0ebd23e4e8c9698fa7345e2d326bcde2d79f5b/diff:/var/lib/docker/overlay2/fee692308edc75f2740372f33c711467a7cf85e33918849ebdd28b57e4eb054b/diff:/var/lib/docker/overlay2/c96832cfc82240a61fdc4ab75eae2d2b443faec05c6e6e246b06affb04c35a1d/diff:/var/lib/docker/overlay2/987581c31599aea072710ccdfece9e7d9d91f278a8d84b9b2ca05b1e342d26cc/diff:/var/lib/docker/overlay2/a85c349db1492490f6d61aeb5de43a3a1900c5f95a99db8f825fe981ece2d116/diff",
7.
1.如果你想要将 Docker 镜像 mytomcat 复制给别人使用,最直接的方法是将镜像导出为一个 tar 文件,然后将该文件提供给他人。以下是如何导出 Docker 镜像的步骤:
-o 选项指定输出文件的名称。• mytomcat:1.0 是要导出的镜像名称和标签。
kt@kt-SYS-4028GR-TR2:~$ sudo docker save -o mytomcat.tar mytomcat:1.0
kt@kt-SYS-4028GR-TR2:~$
2. 检查导出的文件:
确认导出的 tar 文件已经生成在当前目录中:
kt@kt-SYS-4028GR-TR2:~$ ls -lh mytomcat.tar
-rw------- 1 root root 459M Jan 6 16:25 mytomcat.tar
kt@kt-SYS-4028GR-TR2:~$
将 tar 文件提供给他人• 通过文件传输工具:你可以使用文件传输工具(如 FTP、SFTP、Dropbox、Google Drive 等)将 mytomcat.tar 文件发送给他人。• 通过物理介质:如果对方在同一地点,你也可以将文件复制到 USB 驱动器等物理介质中,然后交给对方。对方如何导入镜像对方收到 mytomcat.tar 文件后,可以使用以下命令将 tar 文件导入为 Docker 镜像:
sudo docker load -i mytomcat.tar
• -i 选项指定输入文件的路径。导入后,对方可以使用 docker images 命令查看导入的镜像,并使用 docker run 命令运行该镜像。通过这些步骤,你可以轻松地将 Docker 镜像 mytomcat 导出为一个文件,并提供给他人使用。
操作记录:
kt@kt-SYS-4028GR-TR2:~$ sudo docker save -o mytomcat.tar mytomcat:1.0
kt@kt-SYS-4028GR-TR2:~$ ls -lh mytomcat.tar
-rw------- 1 root root 459M Jan 6 16:25 mytomcat.tar
kt@kt-SYS-4028GR-TR2:~$ sudo images
sudo: images: command not found
kt@kt-SYS-4028GR-TR2:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mytomcat 1.0 bbdd452936a3 16 minutes ago 475MB
tomcat 9.0 39642322f89a 3 weeks ago 469MB
tomcat latest f62f518e5c5c 3 weeks ago 467MB
mongo latest f08e39122805 4 weeks ago 855MB
kibana 7.17.26 86125e209614 4 weeks ago 866MB
nginx latest f876bfc1cc63 5 weeks ago 192MB
centos latest 5d0da3dc9764 3 years ago 231MB
elasticsearch 6.4.0 1ac676545731 6 years ago 791MB
kt@kt-SYS-4028GR-TR2:~$ sudo docker rmi -f mytomcat:1.0
Untagged: mytomcat:1.0
Deleted: sha256:bbdd452936a3063cd369cf12e685ca39df828dae830e44eba9c7bd1d4b418b54
Deleted: sha256:0eeded58289b01f46268c3f1823056cc361033853c54b9bdf3fbc4439b68573f
kt@kt-SYS-4028GR-TR2:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tomcat 9.0 39642322f89a 3 weeks ago 469MB
tomcat latest f62f518e5c5c 3 weeks ago 467MB
mongo latest f08e39122805 4 weeks ago 855MB
kibana 7.17.26 86125e209614 4 weeks ago 866MB
nginx latest f876bfc1cc63 5 weeks ago 192MB
centos latest 5d0da3dc9764 3 years ago 231MB
elasticsearch 6.4.0 1ac676545731 6 years ago 791MB
kt@kt-SYS-4028GR-TR2:~$ sudo docker load -i mytomcat.tar
546175e87c0f: Loading layer 6.714MB/6.714MB
Loaded image: mytomcat:1.0
kt@kt-SYS-4028GR-TR2:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mytomcat 1.0 bbdd452936a3 17 minutes ago 475MB
tomcat 9.0 39642322f89a 3 weeks ago 469MB
tomcat latest f62f518e5c5c 3 weeks ago 467MB
mongo latest f08e39122805 4 weeks ago 855MB
kibana 7.17.26 86125e209614 4 weeks ago 866MB
nginx latest f876bfc1cc63 5 weeks ago 192MB
centos latest 5d0da3dc9764 3 years ago 231MB
elasticsearch 6.4.0 1ac676545731 6 years ago 791MB
kt@kt-SYS-4028GR-TR2:~$
先建,后删除,然后再加载。
再删除本地的。
kt@kt-SYS-4028GR-TR2:~$ ls
anaconda3 Documents kibana-config mytomcat.tar snap 下载
'Clash for Windows-0.20.16-x64-linux' Downloads kibana.yml Pictures Templates
Desktop gitee Music Public Videos
kt@kt-SYS-4028GR-TR2:~$ sudo rm mytomcat.tar
kt@kt-SYS-4028GR-TR2:~$ ls
anaconda3 Documents kibana-config Pictures Templates
'Clash for Windows-0.20.16-x64-linux' Downloads kibana.yml Public Videos
Desktop gitee Music snap 下载
kt@kt-SYS-4028GR-TR2:~$
此过程仅记录。