一。镜像基础
一。基于容器制作镜像
1. 查看并关联运行的容器
[gh@localhost ~]$ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4da438fc9a8e busybox "sh" 2 days ago Up 3 seconds aaaaa [gh@localhost ~]$ docker container attach aaaaa / #
2. 创建文件夹和文件
/ # mkdir /var/html / # vi /var/html/index.html / # cat /var/html/index.html ............ httpd ........... / #
3. 查看httpd服务帮助
/ # which httpd /bin/httpd / # httpd -h -f 前台运行 -h 家目录 / #
4. 制作镜像
---- docker container commit --help
-a:作者信息
-c:修改COMMAND,即容器主程序
-m:说明
-p:暂停容器
[gh@localhost ~]$ docker container commit -a "name <abc@163.com>" -c 'CMD ["/bin/httpd","-f","-h","/var/html"]' -p aaaaa myhttpd:v9.0 sha256:9fdc2c89794f1d716a8ef3c90e4109991210e48fed46fa3f76dd9d35cc2e636f [gh@localhost ~]$ docker image ls |grep "myhttpd" myhttpd v9.0 9fdc2c89794f 18 seconds ago 1.13MB [gh@localhost ~]$
5. 运行镜像
[gh@localhost ~]$ docker container run --name httpd -d myhttpd:v9.0 e51a67a0346bd766b0716d6e0b2f5c101d98d45a0afd04a5b7f6ebc8007c24e1 [gh@localhost ~]$ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e51a67a0346b myhttpd:v9.0 "/bin/httpd -f -h /v…" 6 seconds ago Up 5 seconds httpd 4da438fc9a8e busybox "sh" 2 days ago Up 6 minutes aaaaa [gh@localhost ~]$
6. 访问服务
[gh@localhost ~]$ curl 172.17.0.3
............
httpd
...........
[gh@localhost ~]$
7. 与容器关联
[gh@localhost ~]$ docker container exec -it httpd /bin/sh / # ps -e PID USER TIME COMMAND1 root 0:00 /bin/httpd -f -h /var/html11 root 0:00 /bin/sh16 root 0:00 ps -e / #
8. 登陆阿里云仓库(密码保存在家目录 .docker/config.json)
[gh@localhost ~]$ docker login --username=1596430280@qq.com registry.cn-shenzhen.aliyuncs.com
Password:
Login Succeeded
[gh@localhost ~]$
9. 修改标签(阿里云仓库里有操作说明)
[gh@localhost ~]$ docker image ls |grep "myhttpd" myhttpd v9.0 9fdc2c89794f 13 hours ago 1.13MB [gh@localhost ~]$ docker image tag 9fdc2c89794f registry.cn-shenzhen.aliyuncs.com/ghh/test:v9.9 [gh@localhost ~]$ docker image ls |grep "9fdc2c89794f" myhttpd v9.0 9fdc2c89794f 13 hours ago 1.13MB registry.cn-shenzhen.aliyuncs.com/ghh/test v9.9 9fdc2c89794f 13 hours ago 1.13MB [gh@localhost ~]$
10. 推送镜像
[gh@localhost ~]$ docker image push registry.cn-shenzhen.aliyuncs.com/ghh/test:v9.9 The push refers to repository [registry.cn-shenzhen.aliyuncs.com/ghh/test] 49946ae5d4d2: Pushed 6a749002dd6a: Pushed v9.9: digest: sha256:096ff2618334d8c79750770c1ac20ba6d8f33c6945dafaa7ae17bbbe3eafe5a2 size: 734 [gh@localhost ~]$
11. 登出