Docker鏡像管理基礎

Docker image

    含義:含有啓動容器所需要的文件系統及內容,因此用其創建並啓動docker容器

        1、採用分層構建機制,最底層爲bootfs,其之爲rootfs

        2、bootfs用於系統引導的文件系統,包括bootloader和kernel,容器啓動完成後會被卸載以節約內存資源

        3、rootfs位於bootfs之上,表現爲docker容器的根文件系統

        4、傳統模式中,系統啓動之時,內核掛載rootfs時會首先將其掛載爲“只讀”模式,完整性自檢完成後將其重新掛載爲讀寫模式;

        5、docker中,rootfs有內核掛載爲“只讀”模式,而後通過“聯合掛載”技術額外掛載一個“可寫”層;

    鏡像生成途徑

        1、Dockerfile

        2、基於容器製作

        3、Docker Hub automated builds

    docker commit命令用法

        [root@node1 ~]# docker commit --help

        Usage:  docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]

        Create a new image from a container's changes

        Options:

          -a, --author string    Author (e.g., "John Hannibal Smith <[email protected]>")

          -c, --change list      Apply Dockerfile instruction to the created image

          -m, --message string   Commit message

          -p, --pause            Pause container during commit (default true)


    一,基於容器製作鏡像

        使用busybox啓動一個容器      

        [root@node1 ~]# docker run --name httpd -it busybox

        / # mkdir /data/html -p

        / # cd /data/html/

        /data/html # echo "<h1>web1 server page.</h1>" > /data/html/index.htmlimage.png 

       製作鏡像 

            [root@node1 ~]# docker commit -a "liheng <[email protected]>" -c 'CMD ["/bin/httpd","-f","-h","/data/html"]' -p httpd liheng/httpd:v1

            sha256:c9449a0dfb67341154bd1ac285d7a5dac4bdb19925eeee4dbac218eddbd47b84       image.png

            [root@node1 ~]# docker images

            REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

            liheng/httpd        v1                  c9449a0dfb67        13 seconds ago      1.2MB

            busybox             latest              3a093384ac30        4 weeks ago         1.2MB

            [root@node1 ~]# docker images --no-trunc   

            REPOSITORY          TAG                 IMAGE ID                                                                  CREATED             SIZE

            liheng/httpd        v1                  sha256:c9449a0dfb67341154bd1ac285d7a5dac4bdb19925eeee4dbac218eddbd47b84   17 minutes ago      1.2MB

            busybox             latest              sha256:3a093384ac306cbac30b67f1585e12b30ab1a899374dabc3170b9bca246f1444   4 weeks ago         1.2MB

image.pngimage.png

        使用製作的鏡像創建容器測試       

            [root@node1 ~]# docker run --name httpd1 -d liheng/httpd:v1

            b597aa1740d114d7d09f16eda76e3a2ef1d6847a2b335c71995fe8d0689bb443         

            [root@node1 ~]# docker exec -it httpd1 /bin/sh  

            / # ps

            PID   USER     TIME  COMMAND

            1 root      0:00 /bin/httpd -f -h /data/html

           12 root      0:00 /bin/sh

           17 root      0:00 ps

image.pngimage.png

image.png

        docker host主機上訪問測試

image.png

    二、從鏡像倉庫拉取鏡像

            docker  pull   nginx

            拉取完成後,使用拉取的鏡像啓動一個容器

            docker run --name nginx -d -p 80:80 nginx:latest

            訪問測試

image.png

   

       

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章