docker快速入門_Docker標簽快速入門

docker快速入門

by Shubheksha

通過Shubheksha

Docker標簽快速入門 (A quick introduction to Docker tags)

If you’ve worked with Docker even for a little while, I bet you’ve come across tags. They often look like “my_image_name:1” where the part after the colon is known as a tag. The tag is not always specified when tagging images, but we’ll get to the bottom of that later.

如果您與Docker一起工作了一段時間,我敢打賭您會碰到標簽。 它們通常看起來像“ my_image_name:1”,其中冒號后面的部分稱為標簽。 標記圖像時并不總是指定該標記,但是稍后我們將介紹它。

Ever since I started using Docker, I’ve been very confused about tags. The documentation doesn’t explain them very well, and there really aren’t any thorough explanations on the topic. That’s why I decided to write this post.

自從我開始使用Docker以來,我一直對標簽感到困惑。 該文檔對它們的解釋不是很好,并且對此主題確實沒有任何詳盡的解釋。 這就是為什么我決定寫這篇文章的原因。

什么是Docker標簽? (What are Docker tags?)

So, what exactly are Docker tags? In simple words, Docker tags convey useful information about a specific image version/variant. They are aliases to the ID of your image which often look like this: f1477ec11d12. It’s just a way of referring to your image. A good analogy is how Git tags refer to a particular commit in your history.

那么,Docker標簽到底是什么? 簡而言之,Docker標記傳達有關特定映像版本/變量的有用信息。 它們是圖像ID的別名,通常看起來像這樣: f1477ec11d12 。 這只是引用您的圖片的一種方式。 一個很好的類比是Git標簽如何引用歷史記錄中的特定提交。

The two most common cases where tags come into play are:

標簽起作用的兩種最常見的情況是:

  1. When building an image, we use the following command:

    構建圖像時,我們使用以下命令:
docker build -t username/image_name:tag_name .

Let’s try to unpack what this command does for a bit. We tell the Docker daemon to fetch the Docker file present in the current directory (that’s what the . at the end does). Next, we tell the Docker daemon to build the image and give it the specified tag. If you run docker images, you should see an image whose repository is username/image_name and tag is tag_name.

讓我們嘗試解壓縮該命令的功能。 我們告訴Docker守護進程獲取當前目錄中存在的Docker文件(這就是.結尾的意思)。 接下來,我們告訴Docker守護程序構建映像并為其指定指定標簽。 如果運行docker images ,應該會看到一個鏡像,其存儲庫為username/image_name ,標簽為tag_name

username/image_name is not a mandatory format for specifying the name of the image. It’s just a useful convention to avoid tagging your image again when you need to push it to a registry.

username/image_name不是用于指定圖像名稱的強制格式。 這只是一個有用的約定,可以避免在需要將圖像推送到注冊表時再次對其進行標記。

Your image can be named anything you want. For the public Docker registry, you’re restricted to a two level hierarchy while naming images. For example, your image cannot have the name a/b/c:1. This restriction usually doesn’t exist in private registries. As stated before, it’s not mandatory to specify a tag_name. We’ll see what happens in that case soon.

您的圖像可以命名為任何您想要的名稱。 對于公共Docker注冊表,在命名映像時僅限于兩級層次結構。 例如,您的圖片名稱不能為a/b/c:1. 此限制通常在私人注冊表中不存在。 如前所述,指定tag_name.不是強制性的tag_name. 我們將很快看到在這種情況下會發生什么。

2. Explicitly tagging an image through the tag command.

2.通過tag命令明確標記圖像。

docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

This command just creates an alias (a reference) by the name of the TARGET_IMAGE that refers to the SOURCE_IMAGE. That’s all it does. It’s like assigning an existing image another name to refer to it. Notice how the tag is specified as optional here as well, by the [:TAG] .

此命令僅通過引用SOURCE_IMAGE.TARGET_IMAGE的名稱創建別名(引用) SOURCE_IMAGE. 這就是全部。 這就像為現有圖像分配另一個名稱來引用它一樣。 注意這里的[:TAG]也將標簽指定為可選[:TAG]

如果不指定標簽會怎樣? (What happens when you don’t specify a tag?)

Alright, now let’s uncover what happens when you don’t specify a tag while tagging an image. This is where the latest tag comes into the picture. Whenever an image is tagged without an explicit tag, it’s given the latest tag by default. It’s an unfortunate naming choice that causes a lot of confusion. But I like to think of it as the default tag that’s given to images when you don’t specify one.

好了,現在讓我們發現在標記圖像時未指定標記時會發生什么。 這是latest標簽進入圖片的地方。 每當為圖像添加標簽而沒有顯式標簽時,默認情況下都會為其賦予latest標簽。 這是一個不幸的命名選擇,引起了很多混亂。 但我想將其視為未指定圖像時賦予圖像的默認標記

A lot of confusion around latest is caused due to the expectation that it’s the latest version of the image, especially in Dockerfiles. Let’s consider the various scenarios with an example:

人們對latest的困惑是由于人們期望它是映像的最新版本,尤其是在Dockerfiles中。 讓我們以一個示例來考慮各種場景:

方案1: (Scenario 1:)

Suppose the following statement is present in our Dockerfile:

假設在我們的Dockerfile中存在以下語句:

FROM debian

Since we didn’t specify any tag, Docker will add the latest tag and try to pull the image debian:latest .

由于我們未指定任何標簽,因此Docker將添加latest標簽并嘗試提取圖像debian:latest

方案2: (Scenario 2:)

FROM debian:9.3

Since the tag is explicitly mentioned here, Docker will pull the Debian image tagged 9.3

由于此處已明確提及該標簽,因此Docker將提取標記為9.3的Debian映像。

Another thing to keep in mind is that there is no rule which states that an image needs to have just one tag. An image can have multiple tags and they’re usually used to specify major and minor versions. For example, consider this:

要記住的另一件事是,沒有規則指出圖像只需要一個標簽。 一個圖像可以有多個標簽,它們通常用于指定主要和次要版本。 例如,考慮一下:

At the time of writing this post, the latest tag for the Debian image points to the 9.3 release and the 9 release. This will most likely change in the future whenever the major or minor version is bumped for the image.

在撰寫本文時,Debian映像的latest標簽指向9.3版本 9版本。 每當更改主要或次要版本的映像時,將來這種情況很可能會改變。

Please note that tags being used for semantic versioning is a convention that’s followed, but tags weren’t designed just for that purpose.

請注意,用于語義版本控制的標簽是遵循的約定,但標簽并非僅用于此目的。

總之,最新不是特殊標簽 (In conclusion, latest is not a special tag)

The main takeaway from what we’ve covered so far is that latest is just like any other tag. The onus is on the developer to tag the images properly such that latest always points to the latest stable release of the image.

到目前為止,我們主要介紹的內容是最新的標簽與其他任何標簽一樣 。 開發人員有責任正確標記圖像,以便“ latest始終指向圖像的最新穩定版本。

Hence, we don’t explicitly specify a tag in our Dockerfiles when pulling images, since we might end up with a completely different version of the base image than what we had used before. There is no guarantees about whether it’ll be a major bump or minor bump. Even an old release can be tagged as latest.

因此,在拉取映像時,我們不會在Dockerfile中明確指定標簽,因為我們最終可能會獲得與之前使用的映像完全不同的版本。 不能保證它會是主要顛簸還是次要顛簸。 甚至舊版本也可以標記為latest

P.S. If you found any misconceptions/errors in the post, please feel free to tweet to me @ScribbingOn.

PS:如果您在帖子中發現任何誤解/錯誤,請隨時通過@ScribbingOn向我發送推文。

Thanks to Jér?me Petazzoni for helping me make sense of some of this.

感謝Jér?mePetazzoni幫助我理解了其中的一些內容。

翻譯自: https://www.freecodecamp.org/news/an-introduction-to-docker-tags-9b5395636c2a/

docker快速入門

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/394738.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/394738.shtml
英文地址,請注明出處:http://en.pswp.cn/news/394738.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

動態規劃算法——最長上升子序列

今天我們要講的是最長上升子序列(LIS)。【題目描述】給定N個數,求這N個數的最長上升子序列的長度。【樣例輸入】      【樣例輸出】7        42 5 3 4 1 7 6那么什么是最長上升子序列呢? 就是給你一個序列…

如何快速掌握一門新技術/語言/框架

IT行業中的企業特點是都屬于知識密集型企業。這種企業的核心競爭力與員工的知識和技能密切相關。而如果你在企業中扮演的是工程師的角色的話,那么 你的核心競爭力就是IT相關的知識與技能的儲備情況。而眾所周知,IT行業是一個大量產生新知識的地方&#x…

c語言今天星期幾問題,C語言輸入今天星期幾

滿意答案迷茫03222015.07.24采納率&#xff1a;55% 等級&#xff1a;9已幫助&#xff1a;665人123456789101112131415161718192021#include<stdio.h>int main(void){ enum weekday{ sun, mon, tue, wed, thu, fri, sat }; int n; printf("輸入星期數(0-…

備忘錄模式 詳解

定義 在不破壞封裝性的前提下&#xff0c;捕獲一個對象的內部狀態&#xff0c;并在該對象之外保存這個狀態&#xff1b; 行為型模式 角色 發起人角色&#xff08;Originator&#xff09;&#xff1a;記錄當前時刻的內部狀態&#xff0c;負責定義哪些屬于備份范圍的狀態&#xf…

dll oem證書導入工具_技術干貨 | 惡意代碼分析之反射型DLL注入

歡迎各位添加微信號&#xff1a;qinchang_198231 加入安全 交流群 和大佬們一起交流安全技術01技術概要這是一種允許攻擊者從內存而非磁盤向指定進程注入DLL的技術&#xff0c;該技術比常規的DLL注入更為隱蔽&#xff0c;因為除了不需要磁盤上的實際DLL文件之外&#xff0c;它…

像程序員一樣思考_如何像程序員一樣思考-解決問題的經驗教訓

像程序員一樣思考by Richard Reis理查德里斯(Richard Reis) 如何像程序員一樣思考-解決問題的經驗教訓 (How to think like a programmer — lessons in problem solving) If you’re interested in programming, you may well have seen this quote before:如果您對編程感興趣…

CF908G New Year and Original Order 數位DP

傳送門 看到數據范圍到\(10^{700}\)毫無疑問數位DP。那么我們最重要的問題是如何有效地維護所有數位排序之后的數的值。 對于某一個數\(x\)&#xff0c;設\(f_{x,i} (i \in [1,9])\)表示\(x\)中的所有數位的值\(\geq i\)的數位數量&#xff0c;比如說\(f_{6345982 , 7} 2 , f_…

銳捷亮相GITC:請互聯網企業為我點個贊!

【51CTO.com原創稿件】GITC全球互聯網技術大會已成功舉辦四屆&#xff0c;今年的會議現場依然是摩肩接踵圍觀者眾。圍繞互聯網熱點技術&#xff0c;眾人根據云、大數據、安全、運維、基礎架構的不同主題&#xff0c;各自聚成小圈子展開深入交流。 銳捷的展位在主會場的內側&…

c語言匯編混合編程方法,C語言和匯編語言混合編程方法

摘要&#xff1a; C語言是一種高級的面向過程的開發語言&#xff0c;匯編語言是一種低級的面向機器的編程語言。兩者在程序設計開發方面各有優劣&#xff0c;目前兩者的混合編程得到了廣泛的應用。本文通過具體的實例&#xff0c;說明了混合編程的基本方法&#xff0c;為C語言應…

WPF Slider設置整數

IsSnapToTickEnabled"True" 轉載于:https://www.cnblogs.com/Fred1987/p/6038608.html

api代理提取_了解提取API

api代理提取Interested in learning JavaScript? Get my ebook at jshandbook.com有興趣學習JavaScript嗎&#xff1f; 在jshandbook.com上獲取我的電子書 Since IE5 was released in 1998, we’ve had the option to make asynchronous network calls in the browser using X…

react.lazy 路由懶加載_React lazy/Suspense使用及源碼解析

React v16.6.0已經發布快一年了&#xff0c;為保障項目迭代發布&#xff0c;沒有及時更新react版本&#xff0c;最近由于開啟了新項目&#xff0c;于是使用新的react版本進行了項目開發。項目工程如何搭建&#xff0c;如何滿足兼容性要求&#xff0c;如何規范化等等這里不作為介…

Dart編程語言入門

Dart基礎入門語法介紹&#xff0c;詳細說明可以查看相關視頻《Dart編程語言入門》。 變量與常量 變量 1.使用 var 聲明變量,默認值為 null var a;//null a 10;2.顯示類型聲明 int a;//null a 10;3.使用 var 聲明&#xff0c;可賦予不同類型的值 var a; //null a 10; //int a…

《PHP精粹:編寫高效PHP代碼》——1.1節為什么要使用面向對象編程

本節書摘來自華章社區《PHP精粹&#xff1a;編寫高效PHP代碼》一書中的第1章&#xff0c;第1.1節為什么要使用面向對象編程&#xff0c;作者&#xff1a;&#xff08;美&#xff09;  Davey Shafik&#xff0c;更多章節內容可以訪問云棲社區“華章社區”公眾號查看 1.1 為什…

c語言數據結構系統化,C語言數據結構+數據庫+操作系統

http://cv.qiaobutang.com/post/55c419b20cf2009bd4607795第二部分是專業相關的C &#xff0c;數據庫&#xff0c;操作系統&#xff0c;數據結構。http://c.biancheng.net/cpp/u/shuju/數據(Data)是信息的載體&#xff0c;它能夠被計算機識別、存儲和加工處理。它是計算機程序加…

c語言判斷一個序列是不是另一個的子序列

1 #include <stdio.h>2 #include <string.h>//添加字符串頭文件3 4 int Subsequence(char s[], char t[]) 5 {6 int m,n,i,j;7 n strlen(s); //n表示序列S的長度8 m strlen(t); //m表示序列T的長度9 i0; 10 j0; 11 if (m>…

linux中python如何調用matlab的數據_特征錦囊:如何在Python中處理不平衡數據

今日錦囊特征錦囊&#xff1a;如何在Python中處理不平衡數據? Index1、到底什么是不平衡數據2、處理不平衡數據的理論方法3、Python里有什么包可以處理不平衡樣本4、Python中具體如何處理失衡樣本印象中很久之前有位朋友說要我寫一篇如何處理不平衡數據的文章&#xff0c;整理…

源碼安裝zabbix遇到的報錯集錦

報錯1&#xff1a;checking for mysql_config... configure: error: MySQL library not found 解決辦法&#xff1a;查找mysql_config #find / -name "mysql_config*" /usr/local/mysql/bin/mysql_config 在配置時將原有的 --with-mysql 改為 --with-mysql/usr/loca…

pso算法c++語言代碼,一C++PSO(PSO)算法

收集和變化PSO算法&#xff0c;它可用于參考實施&#xff1a;#include #include #include #include #include #define rand_01 ((float)rand() / (float)RAND_MAX)const int numofdims 30;const int numofparticles 50;using namespace std;//typedef void (*FitnessFunc)(fl…

Hadoop不適合哪些場景 哪些場景適合?

Hadoop設計的目的主要包括下面幾個方面&#xff0c;也就是所謂的適用場景&#xff1a; 1&#xff1a;超大文件 可以是幾百M&#xff0c;幾百T這個級別的文件。 2&#xff1a;流式數據訪問 Hadoop適用于一次寫入&#xff0c;多次讀取的場景&#xff0c;也就是數據復制進去之后&a…