亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專欄INFORMATION COLUMN

走進(jìn)docker(03):如何繞過(guò)docker運(yùn)行hello-world?

robin / 3507人閱讀

摘要:相關(guān)工具本文將用到三個(gè)工具,分別是和。根據(jù)生成的的就是運(yùn)行容器時(shí)需要的東西的集合。使用運(yùn)行該有了后,就可以用來(lái)運(yùn)行該容器了這里直接用的代替命令,如果你自己編譯了的,那么用命令也是一樣的。

上一篇介紹了image的格式,這里我們就來(lái)用一下hello-world這個(gè)image,看怎么輸出和docker run hello-world同樣的內(nèi)容。

相關(guān)工具

本文將用到三個(gè)工具,分別是skopeo、oci-image-tools和runc。

skopeo: 用來(lái)從Docker Hub上拉取image,并保存為OCI格式

oci-image-tools: 包含幾個(gè)用來(lái)操作本地image的工具

runc: 運(yùn)行容器

runc可以用docker自帶的docker-runc命令替代,效果是一樣的,skopeo的安裝可以參考上一篇最后的介紹或者github上的主頁(yè),oci-image-tools的安裝請(qǐng)參考github上的主頁(yè)。

獲取hello-world的image

利用skopeo獲得hello-world的oci格式的image

dev@debian:~/images$ skopeo copy docker://hello-world oci:hello-world
dev@debian:~/images$ tree hello-world/
hello-world/
├── blobs
│?? └── sha256
│??     ├── 0a2ad94772e366c2b7f2266ca46daa0c38efe08811cf1c1dee6558fcd7f2b54e
│??     ├── 78445dd45222097f5f8d5a16e48dc19c4ca162dcdb80010ab6f1ccfc7e2c0fa3
│??     └── 998a60597add14861de504277c0d850e9181b1768011f51c7daaf694dfe975ef
├── oci-layout
└── refs
    └── latest

然后我們看看hello-world這個(gè)image的文件系統(tǒng)都有些什么文件

#利用oci-image-tool unpack,將image解壓到hello-world-filesystem目錄
dev@debian:~/images$ mkdir hello-world-filesystem
dev@debian:~/images$ oci-image-tool unpack --ref latest hello-world hello-world-filesystem
dev@debian:~/images$ tree hello-world-filesystem/
hello-world-filesystem/
└── hello

0 directories, 1 file
dev@debian:~/images$ file hello-world-filesystem/hello
hello-world-filesystem/hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=4999eecfa472a2341b53954c0eca1e893f01305c, stripped

從上面的結(jié)果可以看出,hello-world這個(gè)image就只包含一個(gè)名字叫做hello的靜態(tài)鏈接的可執(zhí)行文件。

根據(jù)image生成runtime的bundle

runtime的bundle就是運(yùn)行容器時(shí)需要的東西的集合。

dev@debian:~/images$ mkdir hello-world-bundle
dev@debian:~/images$ oci-image-tool create --ref latest hello-world hello-world-bundle
dev@debian:~/images$ tree hello-world-bundle
hello-world-bundle
├── config.json
└── rootfs
    └── hello

1 directory, 2 files

從這里生成的bundle可以看出,bundle里面就是一個(gè)配置文件加上rootfs,rootfs里面的東西就是image里面的文件系統(tǒng)部分,config.json是對(duì)容器的描述,比如rootfs的路徑,容器啟動(dòng)后要運(yùn)行什么命令等,后續(xù)介紹runtime標(biāo)準(zhǔn)的時(shí)候再詳細(xì)介紹。

使用runc運(yùn)行該bundle

有了bundle后,就可以用runc來(lái)運(yùn)行該容器了

這里直接用docker的docker-runc代替runc命令,如果你自己編譯了opencontainer的runc,那么用runc命令也是一樣的。

dev@debian:~/images$ cd hello-world-bundle/
#oci-image-tool幫我們生成的config文件版本和runc需要的版本不一致,
#所以這里先將它刪掉,然后用runc spec命令生成一個(gè)默認(rèn)的config文件
dev@debian:~/images/hello-world-bundle$ rm config.json
dev@debian:~/images/hello-world-bundle$ docker-runc spec

#默認(rèn)生成的config里面指定容器啟動(dòng)的進(jìn)程為sh,
#我們需要將它換成我們的hello程序
#這里請(qǐng)用自己熟悉的編輯器修改config.json文件,
#將里面的"args": ["sh"]改成"args": ["/hello"]
dev@debian:~/images/hello-world-bundle$ vim config.json

#然后用runc運(yùn)行該容器,這里命令行里的hello是給容器取的名字,
#可以是任意不和其它容器沖突的字符串
dev@debian:~/images/hello-world-bundle$ sudo docker-runc run hello
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/
結(jié)束語(yǔ)

該篇展示了如何不通過(guò)docker而運(yùn)行hello-world容器,主要目的為了了解鏡像以及runc之間的關(guān)系,同時(shí)也觸發(fā)我們思考一個(gè)問(wèn)題,既然我們可以繞過(guò)docker運(yùn)行容器,那我們?yōu)槭裁催€要用docker呢?

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://www.ezyhdfw.cn/yun/26898.html

相關(guān)文章

  • 走進(jìn)docker系列:開(kāi)篇

    摘要:包含的內(nèi)容本系列主要介紹三個(gè)上的項(xiàng)目由于只介紹核心的東西,所以不會(huì)包含下面這些項(xiàng)目使用語(yǔ)言開(kāi)發(fā),將多個(gè)相關(guān)的容器配置在一起,從而可以同時(shí)創(chuàng)建啟動(dòng)停止和監(jiān)控它們。由于本人時(shí)間安排發(fā)生變化,本系列停止更新,后面不確定是否會(huì)繼續(xù),非常抱歉。 本人docker初學(xué)者,邊學(xué)習(xí)邊總結(jié),一方面加深自己的理解,另一方面希望對(duì)其他想深入了解docker的同學(xué)有所幫助。 由于本人缺乏實(shí)戰(zhàn)經(jīng)驗(yàn),錯(cuò)誤在所難免...

    darkbug 評(píng)論0 收藏0
  • 走進(jìn)docker(01):hello-world的背后發(fā)生了什么?

    摘要:進(jìn)程啟動(dòng)后,就會(huì)按照的標(biāo)準(zhǔn)準(zhǔn)備好相關(guān)運(yùn)行時(shí)環(huán)境,然后啟動(dòng)進(jìn)程。涉及到標(biāo)準(zhǔn)輸入輸出重定向,這里不細(xì)說(shuō)這里是它們之間的交互流程流程對(duì)應(yīng)的文字描述如下客戶端發(fā)送創(chuàng)建容器請(qǐng)求給,收到請(qǐng)求后,發(fā)現(xiàn)本地沒(méi)有相應(yīng)的額,于是返回失敗。 在程序員的世界里,hello world是個(gè)很特殊的存在,當(dāng)我們接觸一門新的語(yǔ)言、新的開(kāi)發(fā)庫(kù)或者框架時(shí),第一時(shí)間想了解的一般都是怎么實(shí)現(xiàn)一個(gè)hello world,然后...

    cikenerd 評(píng)論0 收藏0
  • 走進(jìn)docker(02):image(鏡像)是什么?

    摘要:包含的內(nèi)容一個(gè)由可選和四部分組成。對(duì)于這兩種不同類型的文件格式,標(biāo)準(zhǔn)定義了兩個(gè)新的,分別是和。最新的標(biāo)準(zhǔn)里面并沒(méi)有涉及到,不過(guò)估計(jì)后續(xù)會(huì)加上。 上一篇介紹了hello-world的大概流程,那么hello-world的image里面到底包含了些什么呢?里面的格式是怎么樣的呢? image所包含的內(nèi)容以及格式都是有標(biāo)準(zhǔn)的,由Open Containers Initiative(OCI)負(fù)...

    xiaowugui666 評(píng)論0 收藏0
  • 走進(jìn)docker(07):docker start命令背后發(fā)生了什么?

    摘要:首先來(lái)看看收到客戶端的啟動(dòng)容器請(qǐng)求后,做了些什么。待上面的文件都準(zhǔn)備好了之后,通過(guò)的方式給發(fā)送請(qǐng)求,通知啟動(dòng)容器。主要功能是啟動(dòng)并管理運(yùn)行時(shí)的所有。包含容器中進(jìn)程相關(guān)的一些屬性信息,后續(xù)在這個(gè)容器上執(zhí)行命令時(shí)會(huì)用到這個(gè)文件。 在上一篇介紹過(guò)了docker create之后,這篇來(lái)看看docker start是怎么根據(jù)create之后的結(jié)果運(yùn)行容器的。 啟動(dòng)容器 在這里我們先啟動(dòng)上一篇中...

    Thanatos 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<