您好,登錄后才能下訂單哦!
今天小編給大家分享的是docker將容器做出鏡像的代碼,相信很多人都不太了解,為了讓大家更加了解,所以給大家總結(jié)了以下內(nèi)容,一起往下看吧。一定會(huì)有所收獲的哦。
做出鏡像可以使用commit命令或dockerfile的方式,commit命令比較簡(jiǎn)單,相當(dāng)于docker根據(jù)container內(nèi)部執(zhí)行的命令自動(dòng)生成dockerfile,并進(jìn)行了build,比較適合對(duì)dockerfile不熟悉的用戶;dockerfile比較適合批量處理的場(chǎng)景。
使用docker commit命令做鏡像
1. pull一個(gè)centos6.6的基礎(chǔ)鏡像,并運(yùn)行一個(gè)docker container,然后在其中進(jìn)行定制化(安裝、配置服務(wù)等);
[root@localhost ~]# docker pull centos:6.6 Pulling repository centos 8b44529354f3: Download complete f1b10cd84249: Download complete Status: Downloaded newer image for centos:6.6 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos 6.6 8b44529354f3 4 days ago 202.6 MB centos centos6.6 8b44529354f3 4 days ago 202.6 MB [root@localhost ~]# docker run -i -t centos:6.6 bash [root@b42c1ba929a9 /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var [root@b42c1ba929a9 /]# mkdir /tmp/test.txt [root@b42c1ba929a9 /]# exit exit
接下來,查看一下container的改動(dòng):
[root@localhost ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b42c1ba929a9 centos:6.6 "bash" About a minute ago Exited (0) 22 seconds ago berserk_mcclintock 804a56ce8008 f1b10cd84249 "/bin/echo hello" 22 minutes ago test [root@localhost ~]# docker diff b42c1ba929a9 C /tmp A /tmp/test.txt C /root A /root/.bash_history
2. 執(zhí)行docker commit命令創(chuàng)建一個(gè)鏡像:
[root@localhost ~]# docker commit -m "new container" b42c1ba929a9 yuanhuan/newcontainer1 07b146e0be9e98c253122784c3837dd1604f7692e794f3601dad747d41901cd4 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE yuanhuan/newcontainer1 latest 07b146e0be9e 43 seconds ago 202.6 MB centos 6.6 8b44529354f3 4 days ago 202.6 MB centos centos6.6 8b44529354f3 4 days ago 202.6 MB
3. 登錄docker,并將該鏡像push到docker倉庫:
[root@localhost ~]# docker login Username: yuanhuan Password: Email: yuanhuan_2005@126.com Login Succeeded [root@localhost ~]# docker push yuanhuan/newcontainer1 The push refers to a repository [yuanhuan/newcontainer1] (len: 1) Sending image list Pushing repository yuanhuan/newcontainer1 (1 tags) f1b10cd84249: Image already pushed, skipping 8b44529354f3: Image already pushed, skipping 07b146e0be9e: Image successfully pushed Pushing tag for rev [07b146e0be9e] on {https://cdn-registry-1.docker.io/v1/repositories/yuanhuan/newcontainer1/tags/latest}
關(guān)于docker將容器做出鏡像的代碼就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的參考價(jià)值,可以學(xué)以致用。如果喜歡本篇文章,不妨把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。