xkcd
xkcd

Reputation: 472

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?

Upvotes: 0

Views: 306

Answers (1)

Romain
Romain

Reputation: 21878

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:

Upvotes: 1

Related Questions