Docker image管理基礎

Docker imagehtml

    含義:含有啓動容器所須要的文件系統及內容,所以用其建立並啓動docker容器node

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

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

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

        四、傳統模式中,系統啓動之時,內核掛載rootfs時會首先將其掛載爲「只讀」模式,完整性自檢完成後將其從新掛載爲讀寫模式;ide

        五、docker中,rootfs有內核掛載爲「只讀」模式,然後經過「聯合掛載」技術額外掛載一個「可寫」層;測試

    鏡像生成途徑ui

        一、Dockerfilespa

        二、基於容器製做orm

        三、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 <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)


    一,基於容器製做鏡像

        使用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 <liheng@xxx.xxx>" -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

    2、從鏡像倉庫拉取鏡像

            docker  pull   nginx

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

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

            訪問測試

image.png

相關文章
相關標籤/搜索