docker是属于联合挂载,最上层的为可写成,下面的镜像都为只读挂载的,这个功能创建在特殊的文件系统上,docker info能够看到html
Storage Driver: overlay2 Backing Filesystem: xfs
overlay2这个是一个特殊的文件系统,用来支持联合挂载的功能,可是这个文件系统是创建在xfs的底层文件系统之上的,不一样的系统这里会不同nginx
hub.docker.comdocker
镜像的制做方式json
dockerfilecurl
基于容器制做网站
先启动一个容器,在容器中作好你要作的修改,而后将这个作好修改的可写层打包做为一个镜像,好比:在一个cnetos的基础镜像上,安装一个nginx,将这个可写层使用docker commit命令打包为一个镜像this
示例:阿里云
[root@localhost ~]# docker run --name b1 -i -t busybox / # ls bin dev etc home proc root sys tmp usr var / # mkdir -p /data/html / # vi /data/html/index.html
vi /data/html/index.htmlurl
<h1>Busybox httpd server.</h1>
基于容器制做镜像时,容器应该处于运行状态,由于他是基于容器的可写层作的镜像3d
在起一个终端执行docker commit来基于b1容器的可写层制做镜像-p表示制做时容器为中止状态,预防产生新的数据,形成数据不完整。
[root@localhost ~]# docker commit -p b1 sha256:df073d955fb3f67248c5d95d11ee55fe88b3ffc9b3e742ab4b33eed4a38f90a8 [root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> df073d955fb3 20 seconds ago 1.22MB busybox latest 19485c79a9bb 4 days ago 1.22MB nginx 1.14-alpine 8a2fb25a19f5 5 months ago 16MB
为了引用起来方便使用docker tag加上标签。
[root@localhost ~]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> df073d955fb3 20 seconds ago 1.22MB busybox latest 19485c79a9bb 4 days ago 1.22MB nginx 1.14-alpine 8a2fb25a19f5 5 months ago 16MB [root@localhost ~]# docker tag df073d955fb3 haoran/httpd:v0.1-1 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE haoran/httpd v0.1-1 df073d955fb3 29 minutes ago 1.22MB busybox latest 19485c79a9bb 4 days ago 1.22MB nginx 1.14-alpine 8a2fb25a19f5 5 months ago 16MB [root@localhost ~]# docker tag haoran/httpd:v0.1-1 haoran/httpd:latest [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE haoran/httpd latest df073d955fb3 35 minutes ago 1.22MB haoran/httpd v0.1-1 df073d955fb3 35 minutes ago 1.22MB busybox latest 19485c79a9bb 4 days ago 1.22MB nginx 1.14-alpine 8a2fb25a19f5 5 months ago 16MB
tag是专门的标签管理命令,一个镜像能够有多个标签,id号是同一个,若是没有标签须要引用镜像id号来打标签,docker hub的haoran/httpd仓库,v0.1-1的标签。
[root@localhost ~]# docker run --name t1 -i -t haoran/httpd:v0.1-1 / # ls bin data dev etc home proc root sys tmp usr var / # cat /data/html/index.html <h1>Busybox httpd server.</h1>
进入容器后默认启动的命令是/bin/sh,如今要求只要一运行就执行httpd服务,不在运行/bin/sh,作镜像时修改默认程序
[root@localhost ~]# docker commit -a 'haoran <haoran@keji.com>' -c 'CMD ["/bin/httpd","-f","-h","/data/html"]' -p b1 haoran/httpd:v0.2 sha256:037337399ca851d8721987dc0152596af82937b07da69aed82a09979fe631f54 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE haoran/httpd v0.2 037337399ca8 5 minutes ago 1.22MB [root@localhost ~]# docker run --name t2 haoran/httpd:v0.2
-a表示做者,-c表示将Dockerfile指令应用于建立的映像 ,-p表示在提交期间(建立镜像时)暂停容器(默认为true)
t2这个容器如今运行的只是httpd程序,而且在前台,什么信息都没有输出,在另一个终端上查看这个容器的ip并访问
[root@localhost ~]# docker inspect t2 "Cmd": [ "/bin/httpd", "-f", "-h", "/data/html" ], "IPAddress": "172.17.0.3", [root@localhost ~]# curl 172.17.0.3 <h1>Busybox httpd server.</h1>
先login登录进仓库默认是docker hub
[root@localhost ~]# docker login -u dockerhubname Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@localhost ~]#
在push推镜像
[root@localhost ~]# docker push dockerhubname/httpd The push refers to repository [docker.io/dockerhaoran/httpd] b99a5f8c3472: Pushed 6c0ea40aef9d: Pushed latest: digest: sha256:b9ea9000c75809ac790f40ab7ff9bb0879c2aea3e8a853b0a8bd1e04daeccc58 size: 734
注意标签和仓库名要同样!!!
阿里云推镜像在网站内会有详情