gpt4 book ai didi

docker - 如何确定扩展服务的副本数

转载 作者:行者123 更新时间:2023-12-02 19:55:02 28 4
gpt4 key购买 nike

我有一个docker-compose文件,其中包含2个服务,一个主服务和一个从服务。我希望能够使用以下方法将从属服务扩展到一定数量的实例

docker-compose up --scale slave=N

但是,我必须在主服务中运行的命令上指定的选项之一是期望的从属实例数。例如。如果将slave = 10缩放,则需要在主服务上的命令中设置--num-slaves = 10。

有没有办法从docker-compose文件本身或从定制的入口点shellscript确定给定服务的实例数?

我面临的问题是,由于尚未找到从docker-compose文件格式本身指定缩放实例数的方法,因此我依靠运行命令的人输入缩放因子保持一致,并使该值与我需要告诉主节点期望的值保持一致。信任用户做正确的事是灾难的根源。如果我可以继续让用户在命令行上指定比例值,则需要一种方法来确定运行时该比例值是什么。

最佳答案

scale并未从撰写版本3上添加,但是您可以使用replicas:

version: "3.7"
services:
redis:
image: redis:latest
deploy:
replicas: 1

并使用以下命令运行它:
docker-compose --compatibility up -d

docker-compose 1.20.0 introduces a new --compatibility flag designed to help developers transition to version 3 more easily. When enabled, docker-compose reads the deploy section of each service’s definition and attempts to translate it into the equivalent version 2 parameter. Currently, the following deploy keys are translated:

resources limits and memory reservations
replicas
restart_policy condition and max_attempts


但:

Do not use this in production!

We recommend against using --compatibility mode in production. Because the resulting configuration is only an approximate using non-Swarm mode properties, it may produce unexpected results.



this

PS:

Docker container names must be unique you cannot scale a service beyond 1 container if you have specified a custom name. Attempting to do so results in an error.

关于docker - 如何确定扩展服务的副本数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58617984/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com