编程技术网

关注微信公众号,定时推送前沿、专业、深度的编程技术资料。

 找回密码
 立即注册

QQ登录

只需一步,快速开始

极客时间

Docker服务中的Docker容器ID唯一性:Docker container ID uniqueness in docker service

hkf 云计算 2022-5-10 14:48 7人围观

腾讯云服务器
Docker服务中的Docker容器ID唯一性的处理方法

我已经阅读了如何为容器分配容器ID:容器ID已生成

如何验证Docker ID的唯一性?在哪个游泳池中独一无二?在所有退出的,正在运行的,在所有已删除/删除的,在由特定docker服务创建的所有之中?

我想知道容器ID是否是可重复使用的值,因为它来自一个随机数,一个新容器与另一个容器(退出,删除等)具有完全相同的容器ID的可能性有多大?

另一个相对问题: https://forums.docker.com/t/docker-container-id-uniqueness/5253

更新:能否请您指出验证该容器ID是否已存在的代码以创建一个新的代码?

解决方案

在给定的Docker主机中,该ID必须在当前存在的所有容器(包括已退出和已创建的容器)中唯一.删除后,引擎将不再跟踪容器ID.容器可能会重复使用与以前存在的容器相同的容器ID,但是可能性很低.

完整ID是64个字符的十六进制字符串,它给出16 ^ 64个可能的排列(如果我的计算器正确,则为115792089237316195423570985008687907853269984665640564039457584007913129639936).如果仅跟踪短ID,则为12个字符的十六进制字符串,排列顺序为16 ^ 12(281,474,976,710,656).如果您创建了大量的容器,并且需要历史地且唯一地进行跟踪,那么您可能要使用完整的容器ID.

I have read how the containers are assigned the containers IDs: How the docker container id is generated

How is the docker ID uniqueness verified? And in which pool is it unique? Among all exited, among all running, among all deleted/removed, among all ever created by a specific docker service?

I was wondering whether the container ID is a reusable value, since it comes from a random number, how likely is it that a new container will have exactly the same container ID as another one (exited, deleted etc)?

Another relative issue: https://forums.docker.com/t/docker-container-id-uniqueness/5253

UPDATE: Could you please point me to the code that verifies that if the container ID already exists in creates a new one?

解决方案

The ID needs to be unique within a given docker host among all containers that currently exist (including exited and created containers). Once deleted, the engine no longer tracks the container ID. A container could potentially reuse the same container ID as a previously existing container, but the odds of that are fairly low.

The full ID is a 64 character hex string, which gives 16^64 possible permutations (115792089237316195423570985008687907853269984665640564039457584007913129639936 if my calculator is correct). If you only track the short ID's, that's a 12 character hex string, with 16^12 (281,474,976,710,656) permutations. If you create a significant number of containers and need to track them historically and uniquely, then you may want to use the full container ID.

这篇关于Docker服务中的Docker容器ID唯一性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!

腾讯云服务器 阿里云服务器
关注微信
^