Docker container ID uniqueness in docker service

a 夏天 提交于 2021-01-29 01:37:37

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/52818704/docker-container-id-uniqueness-in-docker-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!