简体   繁体   English

扩展具有多个实例的服务时 docker-compose.yml 中的命令替换

[英]Command substitution in docker-compose.yml when scaling a service with multiple instances

The docker-compose.yml file I am using is following:我正在使用的 docker-compose.yml 文件如下:

services:
  web:
    image: nginx:stable-alpine
    ports:
      - "8080-8130:80"
    volumes:
      - ${TEMPDIR}:/run

I launch 20 containers with the following command:我使用以下命令启动 20 个容器:

TEMPDIR=`mktemp -d` docker-compose up -d --scale web=20

All of the containers launch ok, but they all have the same temp volume mounted at /run, whereas I need each running container to have a unique temp volume.所有容器都可以正常启动,但是它们都在 /run 上安装了相同的临时卷,而我需要每个正在运行的容器都有一个唯一的临时卷。 I understand that the problem is that the above yml file is doing Variable Substitution whereas what I need is Command Substitution but I could not find any way of doing that in the official reference , especially when launching multiple instances of the same docker image.我知道问题在于上面的 yml 文件正在执行变量替换,而我需要的是命令替换,但我在官方 参考中找不到任何方法,特别是在启动同一 docker 图像的多个实例时。 Is there some way to fix this problem?有没有办法解决这个问题?

Maybe what you are looking for is tmpfs .也许您正在寻找的是tmpfs

Mount a temporary file system inside the container.在容器内挂载一个临时文件系统。 Can be a single value or a list.可以是单个值或列表。

You can use it simply like this你可以像这样简单地使用它

services:
  web:
    image: nginx:stable-alpine
    ports:
      - "8080-8130:80"
    tmpfs: /run

Here are the references:以下是参考资料:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM