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
注意標籤和倉庫名要同樣!!!
阿里雲推鏡像在網站內會有詳情