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快速入门

docker快速入门_Docker标签快速入门相关推荐

  1. Docker系列一之基础快速入门企业实战

    1.1什么是LXC LXC为Linux Container的简写.Linux Container容器是一种内核虚拟化技术,可以提供轻量级的虚拟化,以便隔离进程和资源,而且不需要提供指令解释机制以及全虚 ...

  2. Electron 快速开始(一)-入门基础、使用 JavaScript,HTML 和 CSS 构建跨平台的桌面应用程序

    文章目录 Electron 快速开始(一)-入门基础.使用 JavaScript,HTML 和 CSS 构建跨平台的桌面应用程序 Electron简介 多进程模型​ Electron 快速开始 管理窗 ...

  3. python魔力手册-小白入门宝典:Python快速入门魔力手册 PDF 超清版

    给大家带来的一篇关于Python编程相关的电子书资源,介绍了关于小白入门.python入门.Python手册方面的内容,本书是由魔力手册出版,格式为PDF,资源大小11.8 MB,魔力手册编写,目前豆 ...

  4. 0基础入门,如何快速上手Python?

    0基础入门,如何快速上手pythpn 新的改变 因为清晰易读的风格,广泛的适用性,python已经成为最受欢迎的编程语言之一,在TIOBE排行榜位居第四,是名副其实的人工智能第一语言. python ...

  5. 网络编程懒人入门(三):快速理解TCP协议一篇就够

    1.前言 本系列文章的前两篇<网络编程懒人入门(一):快速理解网络通信协议(上篇)>.<网络编程懒人入门(二):快速理解网络通信协议(下篇)>快速介绍了网络基本通信协议及理论基 ...

  6. 网络编程懒人入门(二):快速理解网络通信协议(下篇)

    1.前言 本文上篇<网络编程懒人入门(一):快速理解网络通信协议(上篇)>分析了互联网的总体构思,从下至上,每一层协议的设计思想.基于知识连贯性的考虑,建议您先看完上篇后再来阅读本文. 本 ...

  7. 网络编程懒人入门(一):快速理解网络通信协议(上篇)

    1.写在前面 论坛和群里常会有技术同行打算自已开发IM或者消息推送系统,很多时候连基本的网络编程理论(如网络协议等)都不了解,就贸然定方案.写代码,显得非常盲目且充满技术风险. 即时通讯网论坛里精心整 ...

  8. el-date-picker设置默认日期_ERP入门教程:快速掌握金蝶ERP的基础-物料批次管理的应用及设置...

    ERP入门教程:快速掌握金蝶ERP的基础-物料的批次管理的应用及设置 关注我,我将定期分享更多的ERP解决方案 转发关注并私信我,了解更多的解决方案及操作方法哦 一.应用软件版本:金蝶KIS旗舰版6. ...

  9. 云开发系列课程让你从入门到精通快速上手Serverless和云开发技术

    简介:云开发系列课程主要介绍了从入门到精通快速上手Serverless和云开发技术.学习内容涵盖云开发协同.云函数.云数据库.多媒体托管.前后端一体化框架等Serverless Web开发必备知识.希 ...

最新文章

  1. python程序员需要掌握哪些技术-python运维要掌握哪些内容
  2. Universal Windows Platform(UWP)应用的窗口特性
  3. python标识符和关键字_Python标识符和关键字资料解析
  4. C语言学习之求1+2+3+···+100的值
  5. Semaphore、CountDownLatch和CyclicBarrier
  6. Solaris是出色的Java开发平台的原因
  7. 新工科背景下的大数据体系建设探析
  8. onClientClick 和 onClient 区别
  9. python数据结构-图
  10. Golang爬取网页数据时403
  11. access计算机二级改工号,Access新手来看:如何更改表/窗体/报表...得名字
  12. You must install signalwire-client-c to build mod_signalwire。
  13. linux+mmap父子通信_Linux 系统开发5 进程间通信 pipe() fifo() mmap()
  14. python可视化(十种常用图)
  15. 莫烦python强化学习笔记——Q learning
  16. 2021如何提升网站的排名?SEO
  17. 【公众号】微信进入公众号链接自动获取授权登陆
  18. 【大学生辩论赛】如何练习自己的辩论口才
  19. 雷达波形样式_系统工程与电子技术专栏征稿丨雷达抗干扰技术
  20. OCR--苹果ios安卓android身份证拍照扫描识别sdk

热门文章

  1. 最全面试考点与面试技巧,真香!
  2. Error: Program type already present: okhttp3.Authenticator$1
  3. 结对项目-小学生四则运算系统网页版项目报告
  4. BZOJ 3527: [ZJOI2014]力(FFT)
  5. Codeforces 600E Lomsat gelral (树上启发式合并)
  6. 【BZOJ1857】【SCOI2010】传送带 [三分]
  7. 算法篇---java经典问题!!!
  8. Android 网络通信架构学习
  9. 水晶报表-简单数据类型(Crystal 语法)
  10. mac下 如果docker 如果访问不到网 就下载哥docker-machine 然后进入到vbox下进行操作