Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

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

The docker-compose.yml file I am using is following:

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

I launch 20 containers with the following command:

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. 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. Is there some way to fix this problem?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Maybe what you are looking for is 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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...