I have a situation where I need to create many instances of a docker container, and they should have mounts that enable them to persist their data to different locations, so they aren't all running into each other. The containers are all worker agents for some non-docker-controlled server.
Essentially I need to be able to do something like this:
services:
agent:
volumes:
- /mnt/dat/agent_${DOCKER_SCALE_NUM}:/data/agent
I found a few references when googling around to something like this, but all of them seemed to have a resolution along the lines of "you don't really want to do this" or "here's some other way to solve your problem that doesn't involve doing this".
I doesn't need to be a sequential number or anything like that - I just need some way to get unique mount points for each one.
Is there an existing way to do this? If not, is anything planned?
Thanks!
I have the same use-case, in which I would like to have a variable number of elasticsearch containers, and have each of them write to their own volume, have their own distinct internal name, expose on distinct ports, etc. E.g. a docker-compose definition such as
es:
build: ./es/
restart: unless-stopped
environment:
- node.name=es${DOCKER_SCALE_NUM}
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- es_${DOCKER_SCALE_NUM}:/usr/share/elasticsearch/data
ports:
- ${DOCKER_SCALE_NUM+CONSTANT}:9200
networks:
- elastic
which when running `docker-compose up --scale , I would expect to get 5 containers, 5 volumes with distinct names, 5 different expose ports (starting from some $CONSTANT, e.g. 9199 to make the first container hit the expected 9200 expose port or similar) and a single network they all connect to.
no response yet and no workaround either?
Most helpful comment
I have the same use-case, in which I would like to have a variable number of elasticsearch containers, and have each of them write to their own volume, have their own distinct internal name, expose on distinct ports, etc. E.g. a docker-compose definition such as
which when running `docker-compose up --scale , I would expect to get 5 containers, 5 volumes with distinct names, 5 different expose ports (starting from some $CONSTANT, e.g. 9199 to make the first container hit the expected 9200 expose port or similar) and a single network they all connect to.