如何基于scale id动态绑定docker卷?

kninwzqo  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(245)

我想请您帮助了解如何根据scale id动态绑定/Map外部目录(我的工作站)和内部目录(docker容器)?
例如。:
如果我使用--scale=1,内部目录(docker容器)将是/logs1
如果我使用--scale=2,内部目录将是/logs2
如果我使用--scale=3,内部目录将是/logs3
等等
至于外部目录,没有问题,因为我总是可以创建一个脚本,该脚本将循环docker示例的数量,以创建所有本地目录
这是我的.env文件:


# replace with the absolute path where is located the war file

EDAPI_WAR_LOCAL_PATH=./restapi-war-6.2021.05-RC1.war
EDAPI_WAR_CONTAINER_PATH=/usr/local/tomcat/webapps/restapi.war
MRAS_CONFIG_LOCAL_PATH=./mras-config
MRAS_CONFIG_CONTAINER_PATH=/usr/local/tomcat/config/mras
MRAS_LOG_LOCAL_PATH=./logfiles/mras
MRAS_LOG_CONTAINER_PATH=/usr/local/tomcat/logfiles/mras
SERVER_XML_CONFIG_LOCAL_PATH=./server.xml
SERVER_XML_CONFIG_CONTAINER_PATH=/usr/local/tomcat/conf/server.xml

# hazelcast configuration

HAZELCAST_GROUP=hz-compose
HAZELCAST_GROUP_PWD=XXX
HAZELCAST_CLIENT_SERVER_MODE=true
HAZELCAST_MANCENTER_ENDPOINT=http://mancenter:8080/hazelcast-mancenter

# map name prefix: connect to the same hazelcast cluster with different clients

HAZELCAST_MAP_GROUP_NAME=

# enable if you would like to user mras_2 service

# HAZELCAST_MAP_GROUP_NAME2=

# the token prefixes

TOKEN_PREFIX_MRAS1=
TOKEN_PREFIX_MRAS2=

my docker-compose.yml:

version: '3'
services:
    reverse-proxy:
        image: traefik:v2.3
        command: --api.insecure=true --providers.docker
        ports:
            - "80:80"
            - "9090:8080"
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
        labels:
            - "traefik.enable=false"
    mras:
        image: tomcat:9-jdk8
        volumes:
            - ${MRAS_CONFIG_LOCAL_PATH}:${MRAS_CONFIG_CONTAINER_PATH}
            - ${EDAPI_WAR_LOCAL_PATH}:${EDAPI_WAR_CONTAINER_PATH}
            - ${SERVER_XML_CONFIG_LOCAL_PATH}:${SERVER_XML_CONFIG_CONTAINER_PATH}
            - ${MRAS_LOG_LOCAL_PATH}${SCALE_ID}:${MRAS_LOG_CONTAINER_PATH}${SCALE_ID}
        environment:
            - JPDA_ADDRESS=8000
            - JPDA_TRANSPORT=dt_socket
            - JAVA_OPTS=-Ddebug -Dhazelcast.member.address=hazelcast -Dhazelcast.mancenter.url=${HAZELCAST_MANCENTER_ENDPOINT} -Dgroup.name=${HAZELCAST_GROUP} -Dgroup.password=${HAZELCAST_GROUP_PWD} -Dhazelcast.enableClientServerMode=${HAZELCAST_CLIENT_SERVER_MODE} -Dhazelcast.mapGroupName=${HAZELCAST_MAP_GROUP_NAME} -DtokenPrefix=${TOKEN_PREFIX_MRAS1}
            - SCALE_ID="{DOCKER_HOST}""
        command: ["catalina.sh", "jpda", "run"]
        labels:
            - "traefik.enable=true"
            - "traefik.http.routers.mras-mras-docker.rule=PathPrefix(`/restapi`)"
            - "traefik.http.services.mras-mras-docker.loadbalancer.server.port=8080"
        depends_on:
            - hazelcast
        ports:
            - "19090-19093:8080"
            - "18800-18803:8000"
            - "15910-15913:5910"
        hazelcast:
        image: hazelcast/hazelcast:3.11
        volumes:
            - ./hazelcast-config:/configFolder
        environment:
            - JAVA_OPTS=-Ddebug -Dhazelcast.shutdownhook.policy=GRACEFUL -Dhazelcast.diagnostics.enabled=true -Dhazelcast.config=/configFolder/hazelcast.xml -Dhazelcast.port=5701 -Dhazelcast.mancenter.url=${HAZELCAST_MANCENTER_ENDPOINT} -Dgroup.name=${HAZELCAST_GROUP} -Dgroup.password=${HAZELCAST_GROUP_PWD}
        links:
            - "management-center:mancenter"
        labels:
            - "traefik.enable=false"
    management-center:
        image: hazelcast/management-center:3.11
        environment:
            - JAVA_OPTS=-Dhazelcast.mc.rest.enabled=true
        ports:
            - 8080:8080
        labels:
            - "traefik.enable=false"

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题