I need to deploy a docker stack on several nodes in docker swarm. There are some dynamic values like the path to the ssl certificates which is different for each worker node. I know that I can't pass the values in environment variables because all of the nodes will get the values extracted from the manager node environment.
I searched and I found another question in StackOverflow addressing the same issue. Here is the URL
The solution stated that I should use the command below for each node to set the values.
docker node update --label-add key=value <node-id>
My problem is when I want to read the values in docker-compose.yaml
file I get the error:
service proxy: undefined volume "{{.Node.Labels.Chain}}"
I deploy using the command:
docker stack deploy -c docker-compose.yaml stack_name
Here is the docker-compose.yaml
file:
version: '3'
services:
redis:
image: redis:latest
deploy:
mode: global
restart_policy:
condition: on-failure
networks:
- connector
proxy:
image: myusername/myrepo:${VERSION}
deploy:
mode: global
restart_policy:
condition: on-failure
volumes:
- "{{.Node.Labels.Chain}}:/fullchain.pem"
- "{{.Node.Labels.Key}}:/privkey.pem"
- "${ERROR_LOG}:/err.log"
ports:
- "${HOST_PORT}:${CONTAINER_PORT}"
networks:
- connector
networks:
connector:
I tried different values for version like 3
or 3.4
but didn't help.
I ran the command docker node inspect <HOST_NAME>
and here are the results related to Labels
section:
"Spec": {
"Labels": {
"Chain": "/etc/letsencrypt/live/mydomain.com/fullchain.pem",
"Key": "/etc/letsencrypt/live/mydomain.com/privkey.pem"
},
"Role": "manager",
"Availability": "active"
}
I tried different values for the mount key in docker-compose.yaml
file like {{.Node.Spec.Labels.Chain}}
but they didn't help either.
I'd be grateful if anyone can help me solve the issue.
results of docker version
:
Client:
Version: 18.09.7
API version: 1.39
Go version: go1.10.8
Git commit: 2d0083d
Built: Thu Jun 27 17:56:23 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.7
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 2d0083d
Built: Thu Jun 27 17:23:02 2019
OS/Arch: linux/amd64
Experimental: false