(一)最小的鏡像
鏡像是 Docker 容器的基石,容器是鏡像的運行實體,有了鏡像才能啟動容器,
(1)鏡像的內部結構
? 為什么我們要討論鏡像的內部結構?如果只是使用鏡像,當然不需要了解,直接通過 docker 命令下載和運行就可以了,但如果我們想創建自己的鏡像,或者想理解 Docker 為什么是輕量級的,就非常有必要學習這部分知識了,
(2)hello-word最小的鏡像
? hello-world 是 Docker 官方提供的一個鏡像,通常用來驗證 Docker 是否安裝成功,我們先通過 docker pull 從 Docker Hub 下載它,
root@cuiyongchao:~# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
0e03bdcc26d7: Already exists
Digest: sha256:8c5aeeb6a5f3ba4883347d3747a7249f491766ca1caa47e5da5dfcf6b9b717c0
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
root@cuiyongchao:~#
? 通過docker images 命令查看鏡像詳細資訊:
root@cuiyongchao:~# docker images hello-world
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 9 months ago 13.3kB
root@cuiyongchao:~#
? 使用docker run運行容器:
root@cuiyongchao:~# docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
? 其實我們更關心 hello-world 鏡像包含哪些內容,
? Dockerfile 是鏡像的描述檔案,定義了如何構建 Docker 鏡像,Dockerfile 的語法簡潔且可讀性強,后面我們會專門討論如何撰寫 Dockerfile,hello-world 的 Dockerfile 內容如下:
FROM scratch
COPY hello /
CMD ["/hello"]
-
FROM scratch,此鏡像是從白手起家,從 0 開始構建,
-
COPY hello /,將檔案“hello”復制到鏡像的根目錄,
-
CMD ["/hello"],容器啟動時,執行 /hello
鏡像 hello-world 中就只有一個可執行檔案 “hello”,其功能就是列印出 “Hello from Docker ......” 等資訊, /hello 就是檔案系統的全部內容,連最基本的 /bin,/usr, /lib, /dev 都沒有,hello-world 雖然是一個完整的鏡像,但它并沒有什么實際用途,通常來說,我們希望鏡像能提供一個基本的作業系統環境,用戶可以根據需要安裝和配置軟體,這樣的鏡像我們稱作 base 鏡像,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/196012.html
標籤:其他
上一篇:喜報:恭喜騰訊云 API 網關獲得國內首張可信云認證證書
下一篇:容器技術(三)base鏡像【5】
