docker容器主机名顺序号 [英] docker container hostname sequential number

查看:176
本文介绍了docker容器主机名顺序号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在docker swarm中,如果有副本/规模,是否可以选择主机名/容器名具有一些序列号?

Is there any option to have the hostname / containername to have some seq numbers in case of replicas/scale in docker swarm?

version: '3'

services:

  serA:
    image: someimage1
    hostname: serA
  serB:
    image: someimage2
    tty: true
    hostname: serB{{.Node.index}}
    deploy:
      replicas: 2

例如,我想将主机名设置为 serB1 serB2

For ex: I would like to have the hostnames as serB1 and serB2

推荐答案

AFAIK不支持,并且不会被支持,因为Docker团队认为这是一个坏主意:

AFAIK this is not supported and won't be supported as the Docker team thinks it's a bad idea:


经过一番思考,我认为这不是一个好主意。

After some thought, I don't think this is a good idea.

我们可能会将来要摆脱规模数字。一旦我们使用Swarm迁移到多主机系统,跟踪整数递增序列将变得(a)代价高昂(b)不可靠。

We might well get rid of scale numbers in future. Once we move to multi-host systems with Swarm, keeping track of an incrementing sequence of integers will become (a) costly and (b) unreliable.

即使我们保留了比例数,我我不相信依靠它们在容器之间分配工作是个好主意。最好让容器生成自己的标识符并使​​用它,因此它不依赖于Compose正常工作。

Even if we kept scale numbers, I'm not convinced it's a good idea to rely on them for dividing up work between containers. Better for the container to generate an identifier of its own and use that, so it's not dependent on Compose to work properly.

...

回顾一些讨论:


  • $(hostname)或$(hostname -i)可用于获取唯一ID,或者缩放容器的IP地址。使用此操作不会复制图像,而是在容器运行时对其进行评估。

  • $(hostname) or $(hostname -i) can be used to get a unique id, or the ip address of a scaled container. Using this does not duplicate images, it's evaluated at container run time.

我们要删除顺序比例尺ID,仅使用容器ID的唯一性。它们在分布式系统中不可靠

we'd like to remove the sequential scale ids and only use the uniqueness of the container ids. They are not reliable in a distributed system

请参见 https://github.com/docker/compose/pull/1131 https://github.com/docker/compose/pull/1371

这篇关于docker容器主机名顺序号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆