1.背景
類似于電腦,要在朋友的電腦上跑你寫的Java程序,就得檢查他電腦有沒有安裝Java環(huán)境.
類似的,要想在別的電腦上跑你寫的Python程序,又得檢查那臺電腦有沒有裝python.
如何讓自己寫的程序換到別的電腦上后,可以便捷的運行起來?
將程序和程序的環(huán)境打包遷移,是一種解決方案.
- 為啥不用虛擬機(jī)?
虛擬機(jī)安裝太麻煩,就好比一個完整的操作系統(tǒng),啟動起來很費時間.
所以,你可以簡單的理解為:Docker就是一個輕量級的虛擬機(jī)(只虛擬你需要的軟件運行環(huán)境,冗余的一點都不要).
- 網(wǎng)上看到的另一個Docker入門網(wǎng)站,還不錯.
2.安裝
服務(wù)器版本:CentOS 8.2 64位
2.1 安裝yum-utils
<code-box id="5Jkf7F" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_1 mCS-autoHide" highlighted="true" id="pre-5Jkf7F" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-nYRwi2" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">yum install -y yum-utils</code-pre>
</pre></code-box>
2.2 yum配置阿里Docker源
<code-box id="KDdcjB" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_2 mCS-autoHide" highlighted="true" id="pre-KDdcjB" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-6aTiBE" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</code-pre>
</pre></code-box>
解決problem with installed package podman-1.6.4-10.的報錯
<code-box id="r7D6F2" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_3 mCS-autoHide" highlighted="true" id="pre-r7D6F2" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-8TbCZ3" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">yum erase podman buildah</code-pre>
</pre></code-box>
解決yum命令報錯問題
[圖片上傳失敗...(image-7e83a5-1663643704610)]
2.3 安裝Docker
<code-box id="XyBS3C" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_4 mCS-autoHide" highlighted="true" id="pre-XyBS3C" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-6ERPkZ" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># docker的三個組件: docker-ce蝙场、docker-ce-cli望忆、containerd.io
--nobest不只使用最佳選擇的軟件包 --skip-broken跳過無法安裝的軟件包
yum install -y docker-ce docker-ce-cli containerd.io --nobest</code-pre>
</pre></code-box>
2.4 查看Docker版本
<code-box id="GHQXhy" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_5 mCS-autoHide" highlighted="true" id="pre-GHQXhy" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-tNcEpj" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 簡單信息
docker -v
查看docker的版本號验毡,包括客戶端、服務(wù)端、依賴的Go等
docker version
查看系統(tǒng)(docker)層面信息,包括管理的images, containers數(shù)等
docker info</code-pre>
</pre></code-box>
2.5 擴(kuò)展
1.為啥安裝yum-utils?
為了使用yum-config-manager命令, 執(zhí)行--add-repo操作.
2.添加阿里docker源干嘛?
在最開始的時候框全,我們的yum倉庫里的docker安裝包是上面的幾個,執(zhí)行了yum源添加后干签,阿里帶過來了新的docker安裝包津辩。
[圖片上傳失敗...(image-4253f4-1663643704610)]
3.阿里鏡像站
4.docker三個組件的區(qū)別
containerd.io、docker-ce-cli容劳、docker-ce的區(qū)別
3.Docker服務(wù)相關(guān)
3.1 啟動
<code-box id="wWcMhm" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_6 mCS-autoHide" highlighted="true" id="pre-wWcMhm" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-hTKaXn" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 啟動
systemctl start docker
開機(jī)自啟
systemctl enable docker
禁用開機(jī)自啟
systemctl disable docker
docker服務(wù)是否開機(jī)自啟
systemctl is-enabled docker
已啟動的服務(wù)列表
systemctl list-unit-files|grep enabled</code-pre>
</pre></code-box>
3.2 停止
<code-box id="JtanTr" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_7 mCS-autoHide" highlighted="true" id="pre-JtanTr" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-hCzh6T" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">systemctl stop docker</code-pre>
</pre></code-box>
3.3 重啟
<code-box id="bZJAaZ" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_8 mCS-autoHide" highlighted="true" id="pre-bZJAaZ" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-zrybGY" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">systemctl restart docker</code-pre>
</pre></code-box>
3.4 查看docker狀態(tài)
<code-box id="ndxF8K" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_9 mCS-autoHide" highlighted="true" id="pre-ndxF8K" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-W6fxQW" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">systemctl status docker</code-pre>
</pre></code-box>
4.Docker主要概念
類比win
鏡像: 程序安裝包
容器: 安裝好的程序
(鏡像的)倉庫: 放安裝包的倉庫.
4.1 倉庫喘沿、鏡像和容器
-
鏡像
程序安裝包
Docker鏡像里包含了已打包的應(yīng)用程序及其所依賴的環(huán)境。它包含應(yīng)用程序可用的文件系統(tǒng)和其他元數(shù)據(jù)竭贩,如鏡像運行時的可執(zhí)行文件路徑摹恨。
-
鏡像倉庫
安裝包的倉庫
Docker鏡像倉庫用于存放Docker鏡像,以及促進(jìn)不同人和不同電腦之間共享這些鏡像娶视。當(dāng)編譯鏡像時晒哄,要么可以在編譯它的電腦上運行,要么可以先上傳鏡像到一個鏡像倉庫肪获,然后下載到另外一臺電腦上并運行它寝凌。某些倉庫是公開的,允許所有人從中拉取鏡像孝赫,同時也有一些是私有的较木,僅部分人和機(jī)器可接入。
-
容器
安裝好的軟件
Docker容器通常是一個Linux容器青柄,它基于Docker鏡像被創(chuàng)建伐债。一個運行中的容器是一個運行在Docker主機(jī)上的進(jìn)程预侯,但它和主機(jī),以及所有運行在主機(jī)上的其他進(jìn)程都是隔離的峰锁。這個進(jìn)程也是資源受限的萎馅,意味著它只能訪問和使用分配給它的資源(CPU、內(nèi)存等)虹蒋。
4.2 打包糜芳、分發(fā)和部署
-
打包
制作鏡像
把你軟件本身、所需要的依賴魄衅、三方庫等制作成一個"安裝包"
-
分發(fā)
上傳鏡像倉庫
將安裝包上傳到軟件倉庫,別人可以方便的下載和安裝
-
部署
啟動鏡像,獲得運行著的容器.win開發(fā)好后.
拿著下載好的安裝包,用命令行運行起來(安裝包中帶著運行環(huán)境)
4.3 一個簡單的流程
4.2.1 開發(fā)者在開發(fā)環(huán)境(本地機(jī)器)開發(fā)好應(yīng)用后,制作出鏡像峭竣。
Docker執(zhí)行命令,在本地機(jī)器構(gòu)建出鏡像并存儲晃虫。
4.2.2 開發(fā)者執(zhí)行上傳鏡像命令,上傳本地鏡像到鏡像倉庫.
Docker收到命令后皆撩,將本地鏡像上傳到鏡像倉庫。
4.2.3 開發(fā)者向生產(chǎn)環(huán)境(遠(yuǎn)端服務(wù)器)發(fā)送運行鏡像命令.
生產(chǎn)環(huán)境服務(wù)器收到命令后哲银,Docker會從鏡像倉庫拉取鏡像扛吞,然后基于鏡像運行容器。
5.鏡像相關(guān)
類比win: 程序的安裝包
5.1 查看鏡像
<code-box id="X2PBcr" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_10 mCS-autoHide" highlighted="true" id="pre-X2PBcr" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-ybrney" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker images</code-pre>
</pre></code-box>
5.2 搜索鏡像
<code-box id="mTyms4" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_11 mCS-autoHide" highlighted="true" id="pre-mTyms4" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-5hFw3d" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker search 鏡像名稱</code-pre>
</pre></code-box>
5.3 拉取鏡像
<code-box id="aKDzc8" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_12 mCS-autoHide" highlighted="true" id="pre-aKDzc8" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-yd6eXW" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker pull 鏡像名稱:版本號</code-pre>
</pre></code-box>
5.4 刪除鏡像
<code-box id="X46AGC" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_13 mCS-autoHide" highlighted="true" id="pre-X46AGC" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-MM874w" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker rmi 鏡像名稱:版本號</code-pre>
</pre></code-box>
5.5 其他
5.5.1 鏡像信息
<code-box id="dmNy2a" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_14 mCS-autoHide" highlighted="true" id="pre-dmNy2a" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-TM6Rm3" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">vim /var/lib/docker/image/overlay2/repositories.json</code-pre>
</pre></code-box>
[圖片上傳失敗...(image-1a5d2d-1663643704609)]
repositories.json文件中保存了一些基本信息
[圖片上傳失敗...(image-183c9b-1663643704609)]
6.容器相關(guān)
類比win: 已經(jīng)安裝好的程序
6.1 查看容器列表
<code-box id="sjfz7Y" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_15 mCS-autoHide" highlighted="true" id="pre-sjfz7Y" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-JER5xG" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 查看正在運行的容器
docker ps
查看所有容器
docker ps -a</code-pre>
</pre></code-box>
6.2 創(chuàng)建容器
容器創(chuàng)建后,在容器列表中即可看到該容器(相當(dāng)于安裝好程序)
以后用后文的啟盘榨、停、刪就可以操作該容器了.
<code-box id="J87Y6P" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_16 mCS-autoHide" highlighted="true" id="pre-J87Y6P" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-n5JF5w" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># eg: \是換行的意思
docker run -d -p 1337:1337
--network kong-net
--name konga
-e "NODE_ENV=production"
-e "DB_ADAPTER=postgres"
-e "DB_URI=postgresql://kong:kong@172.0.0.1:5432/konga"
pantsel/konga</code-pre>
</pre></code-box>
linux中-和--的區(qū)別?
-后面一般跟簡寫,大多數(shù)是一個字母,如:
<code-box id="2ApHdh" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_17 mCS-autoHide" highlighted="true" id="pre-2ApHdh" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-b8A2H8" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">ls -l</code-pre>
</pre></code-box>
--后面一般跟長的完整名字,如:
<code-box id="tpzseK" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_18 mCS-autoHide" highlighted="true" id="pre-tpzseK" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-EdfSFz" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">chkconfig --add</code-pre>
</pre></code-box>
run參數(shù)
-
-rm
在容器退出時自動清理容器內(nèi)部的文件系統(tǒng)
在Docker容器退出時,默認(rèn)容器內(nèi)部的文件系統(tǒng)仍然被保留,以方便調(diào)試并保留用戶數(shù)據(jù).
但是,對于前臺運行的容器,由于其只是在開發(fā)調(diào)試過程中短期運行,其用戶數(shù)據(jù)并無保留的必要.
啟動時設(shè)置-rm選項蟆融,這樣在容器退出時就能夠自動清理容器內(nèi)部的文件系統(tǒng).
-
-i
保持容器運行
-
-p
端口映射
-
-e
傳遞環(huán)境變量
-
-t
為容器重新分配一個偽輸入終端
-
-d
以守護(hù)進(jìn)程模式運行容器草巡,退出后容器不會停止
-
-it
創(chuàng)建一個交互式容器,推出后容器容器停止運行
-
-id
創(chuàng)建一個守護(hù)容器型酥;退出后容器不停止運行
-
–-name
為創(chuàng)建的容器命名
6.3 進(jìn)入容器
<code-box id="C8bwRe" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_19 mCS-autoHide" highlighted="true" id="pre-C8bwRe" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-7cRjhh" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker exec -it 容器名稱 /bin/bash
eg:進(jìn)入一個叫konga的容器
docker exec -it konga /bin/bash
在容器中執(zhí)行了一個ping命令
ping 127.0.0.1
退出當(dāng)前容器
exit</code-pre>
</pre></code-box>
6.4 啟動容器
<code-box id="ZwBccE" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_20 mCS-autoHide" highlighted="true" id="pre-ZwBccE" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-Gn8EEz" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker start 容器名稱</code-pre>
</pre></code-box>
6.5 停止容器
<code-box id="4whFZF" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_21 mCS-autoHide" highlighted="true" id="pre-4whFZF" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-kyrPX5" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker stop 容器名稱</code-pre>
</pre></code-box>
6.6 刪除容器
<code-box id="icP7XA" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_22 mCS-autoHide" highlighted="true" id="pre-icP7XA" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-QwDTtc" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker rm 容器名稱
刪除所有容器
docker rm docker ps -aq
</code-pre>
</pre></code-box>
6.7 查看容器詳細(xì)信息
inspect 視察山憨、檢查
<code-box id="7xEX4m" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_23 mCS-autoHide" highlighted="true" id="pre-7xEX4m" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-mFDYTX" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker inspect 容器名稱</code-pre>
</pre></code-box>
6.8 其他
6.8.1 容器文件位置
<code-box id="frNNH5" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_24 mCS-autoHide" highlighted="true" id="pre-frNNH5" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-Zh2ynt" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">cd /var/lib/docker/containers</code-pre>
</pre></code-box>
[圖片上傳失敗...(image-c33118-1663643704607)]
查看所有容器,其中的id:
eb67258c80d1
與上方文件夾對應(yīng)
<code-box id="WHmSs6" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_25 mCS-autoHide" highlighted="true" id="pre-WHmSs6" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-dXzpzw" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker ps -a
顯示
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
eb67258c80d1 mongo "docker-entrypoint.s…" 7 days ago Exited (0) 6 days ago mongo</code-pre>
</pre></code-box>
6.8.2 從容器里拷貝文件(出來到)宿主機(jī)
手動拷貝,后面可以使用-v命令直接掛載(映射)數(shù)據(jù)弥喉。
<code-box id="TDmCm5" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_26 mCS-autoHide" highlighted="true" id="pre-TDmCm5" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-wCsWaQ" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker cp CONTAINERID:/path/file.type /home
eg: 拷貝eb67258c80d1中的/home/test.txt到宿主機(jī)的/home文件夾下
docker cp eb67258c80d1:/home/test.txt /home
容器停止了也可以拷貝,只要容器還在,容器里面的文件就也還在.</code-pre>
</pre></code-box>
7.網(wǎng)絡(luò)相關(guān)
容器可以比擬做一個獨立的系統(tǒng)環(huán)境,能配置自己網(wǎng)絡(luò),所以說容器里的localhost不一定等于宿主機(jī)的localhost
網(wǎng)絡(luò)模式
bridge:橋接docker(默認(rèn)創(chuàng)建時,不指定網(wǎng)絡(luò)驅(qū)動,將使用bridge模式)
none:不配置網(wǎng)絡(luò)
-
host:和宿主機(jī)共享網(wǎng)絡(luò)
例如:當(dāng)你在容器上使用80端口訪問其他應(yīng)用,使用的是宿主機(jī)的80端口.
container:容器網(wǎng)絡(luò)連通(用的少郁竟,局限很大)
Linux查看網(wǎng)絡(luò)信息
<code-box id="tQBa8m" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_27 mCS-autoHide" highlighted="true" id="pre-tQBa8m" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-66Ewwc" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># if沒有打錯.
這里面能看到docker相關(guān)的網(wǎng)絡(luò).
ifconfig</code-pre>
</pre></code-box>
7.1 查看docker下的網(wǎng)絡(luò)列表
<code-box id="mPsG4B" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_28 mCS-autoHide" highlighted="true" id="pre-mPsG4B" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-BexXN4" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker network ls</code-pre>
</pre></code-box>
7.2 查看單個網(wǎng)絡(luò)詳細(xì)信息
<code-box id="ZnWcrC" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_29 mCS-autoHide" highlighted="true" id="pre-ZnWcrC" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-ZZQ7yb" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker network inspect networkname</code-pre>
</pre></code-box>
7.3 創(chuàng)建網(wǎng)絡(luò)
<code-box id="nTxz2z" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_30 mCS-autoHide" highlighted="true" id="pre-nTxz2z" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-zQdeWc" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 不指定網(wǎng)絡(luò)驅(qū)動時,默認(rèn)創(chuàng)建的是bridge網(wǎng)絡(luò).
docker network create networkname</code-pre>
</pre></code-box>
7.4 刪除網(wǎng)絡(luò)
<code-box id="K2Hc2Y" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_31 mCS-autoHide" highlighted="true" id="pre-K2Hc2Y" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-SrktPd" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker network rm networkname</code-pre>
</pre></code-box>
8.日志相關(guān)
<code-box id="JGJ5ep" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_32 mCS-autoHide" highlighted="true" id="pre-JGJ5ep" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-PMzAmS" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">docker logs [OPTIONS] CONTAINER
Options參數(shù)
--details: 顯示更多的信息
--follow(-f): 跟蹤實時日志
--since string: 顯示自某個timestamp之后的日志,或相對時間由境,如40m(即40分鐘)
--tail string: 從日志末尾顯示多少行日志棚亩, 默認(rèn)是all
--timestamps(-t): 顯示時間戳
--until string: 顯示自某個timestamp之前的日志,或相對時間虏杰,如40m(即40分鐘</code-pre>
</pre></code-box>
示例
<code-box id="b5AYj4" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_33 mCS-autoHide" highlighted="true" id="pre-b5AYj4" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-MZc35e" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 查看容器mysql 最近30分鐘的日志:
docker logs --since 30m mysql
查看容器mysql 某時間之后的日志:
docker logs -t --since="2019-11-02T13:23:37" mysql
查看容器mysql 某時間段日志:
docker logs -t --since="2019-11-02T13:23:37" --until "2019-11-03T12:23:37" mysql</code-pre>
</pre></code-box>
9.配置國內(nèi)加速
9.1 手動修改
<code-box id="ytY4hH" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_34 mCS-autoHide" highlighted="true" id="pre-ytY4hH" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-hhYJ7H" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">vim /etc/docker/daemon.json
加入鏡像信息,注意不要有這行注釋,json是不支持注釋的,不然啟動會報錯
{
"registry-mirrors" : [
"https://mirror.ccs.tencentyun.com",
"http://registry.docker-cn.com",
"http://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
],
"insecure-registries" : [
"registry.docker-cn.com",
"docker.mirrors.ustc.edu.cn"
],
"debug" : true,
"experimental" : true
}</code-pre>
</pre></code-box>
重啟docker
<code-box id="PXjzB4" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_35 mCS-autoHide" highlighted="true" id="pre-PXjzB4" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-GK85Zd" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">systemctl restart docker.service</code-pre>
</pre></code-box>
鏡像說明
<code-box id="6MPfsk" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_36 mCS-autoHide" highlighted="true" id="pre-6MPfsk" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-Nxkmzt" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);">"https://mirror.ccs.tencentyun.com" //騰訊
"http://registry.docker-cn.com" //docker官方提供的中國鏡像
"http://docker.mirrors.ustc.edu.cn" //中國科學(xué)技術(shù)大學(xué)
"http://hub-mirror.c.163.com" //網(wǎng)易</code-pre>
</pre></code-box>
9.2 DaoCloud鏡像站
Linux
<code-box id="x7iFYM" style="padding: 0px; margin: 0px; color: rgb(34, 34, 34); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-size: 15.5px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgba(255, 255, 255, 0.9); text-decoration-style: initial; text-decoration-color: initial; position: relative; display: block;"><pre class="highlighter-hljs mCustomScrollbar _mCS_37 mCS-autoHide" highlighted="true" id="pre-x7iFYM" style="padding: 10px !important; margin: 5px 0px; transition-duration: 0.2s; transition-property: color, opacity, padding-top, padding-bottom, margin-top, margin-bottom, height; overflow: visible; touch-action: pinch-zoom; font-size: 14px !important; font-weight: 400; font-family: "Ubuntu Mono", monospace !important; white-space: pre; overflow-wrap: break-word; border-radius: 4px !important; word-break: break-all; counter-reset: itemcounter 0; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); position: relative;">
<code-pre class="code-pre code-pre-line" id="pre-fcSMKW" style="padding: 0px 0px 0px 10px; margin: 0px; position: relative; display: block; left: 30px; border-left: 1px solid rgb(153, 153, 153);"># 下載sh腳本 手動下載瀏覽器訪問: https://get.daocloud.io/daotools/set_mirror.sh</code-pre>
</pre></code-box>