How to specify an iterator in a volume path when using docker-compose to extend a service?

Background: I use docker-compose to host the tomcat service in a cluster of a swock cluster, but I am now struggling with how I will access the registration directory, given that I want to scale the service, but keep the logging directory unique.

Consider a (explicitly) compiled docker composition that simply launches tomcat and mounts a file registration system in which you can record logs.

version: '2' services: tomcat: image: "tomcat:latest" hostname: tomcat-example command: /start.sh volumes: - "/data/container/tomcat/logs:/opt/tomcat/logs,z"

Version

  • docker 1.11
  • docker-compose 1.7.1
  • API version 1.21

Problem: I want to understand how I would like to insert a variable in the "volume" log path so that the log directory is unique for each instance of the scaled service

eg,

 volumes: - "/data/container/tomcat/${container_name}/logs:/opt/tomcat/logs,z" 

I see that based on the name of the project (or the directory I am in) the name of the container is actually known, so can I use this?

for example, setting the project name to "tomcat" and running docker-compose scale tomcat=2 , I will see the following containers.

  • hostname / tomcat _1
  • hostname / tomcat _2

So I can use this as a variable in the logging volume, other suggestions or approaches are welcome. I understand that I can just specify the relative path and let container_id take care of this, but now if I attach splunk or logstash to the logging devices, I will need to know which ones are really logging devices and not the basic f / s containers. However, ideally, I am looking for a specific absolute path here.

Thanks in advance dockers! R.

+7
docker docker-compose docker-swarm scale volume
source share

No one has answered this question yet.

See similar questions:

2
Scaling persistent named volumes in docker-compose

or similar:

nineteen
The difference between the service and the container in the docker
8
How to get to additional containers by hostname after the docker scale?
6
Docker consists of volume reuse
5
Create named docker volume with docker-compose?
4
Relative way with dockers - collecting shared volumes
3
independent volume scaling docker service
2
Scaling persistent named volumes in docker-compose
2
Unable to set volume using docker
0
Scaling docker containers in Rancher with different but persistent volumes
0
Docker Compose Relative Ways vs. Docker Volume

All Articles