有没有办法在docker-compose.yml
文件中使用Docker templates?我创建了一个图像来设置自动rabbitmq集群。 service create
命令如下所示:
docker service create \
--name="rabbitmq" \
--network="rabbitmq" \
--publish 15672:15672 \
--update-delay 2m \
--hostname="{{.Service.Name}}-{{.Task.Slot}}" \
--secret source=key.rabbitmq.pem,target=key.pem \
--secret source=cert.rabbitmq.pem,target=cert.pem \
--mount type=volume,volume-driver=cloudstor:azure,source={{.Service.Name}}-{{.Task.Slot}},destination=/var/lib/rabbitmq/data \
-e SERVICE_NAME="{{.Service.Name}}" \
-e RABBITMQ_ERLANG_COOKIE=xxx \
-e RABBITMQ_MNESIA_DIR=/var/lib/rabbitmq/data \
--with-registry-auth \
registry.tld/rabbitmq
要点是mount
,我想在docker-compose.yml
文件中配置:
rabbitmq:
image: "registry.tld/rabbitmq"
ports: ["15672:15672"]
hostname: "{{.Service.Name}}-{{.Task.Slot}}"
secrets:
- source: key.rabbitmq.pem
target: key.pem
- source: cert.rabbitmq.pem
target: cert.pem
environment:
- SERVICE_NAME: "{{.Service.Name}}"
- RABBITMQ_ERLANG_COOKIE: "cluster"
- RABBITMQ_MNESIA_DIR: "/var/lib/rabbitmq/data"
volumes:
- type: volume
source: "{{.Service.Name}}-{{.Task.Slot}}"
target: "/var/lib/rabbitmq/data"
我甚至不确定普通模板字符串是否有效,但有没有办法定义卷?
因为这显然不起作用:
volumes:
"{{.Service.Name}}-{{.Task.Slot}}": { driver: "cloudstor:azure" }
谢谢你的建议!
答案 0 :(得分:0)
尝试在您的顶级卷中定义如下内容:
volumes:
volume_data:
name: '{{.Service.Name}}_DataVol-{{.Task.Slot}}'
然后在您的服务中安装卷:
volumes:
- "data_volume:/my_app/data"
干杯