Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am moving from
docker-compose
to
docker stack
I am trying to launch my database on my
worker node
from my
manager node
so I am using a
docker-stack.yml
file
on the manager I use command:
docker stack deploy -c docker-stack.yml mr
I get error:
* error decoding 'Volumes[0]': invalid spec: :/docker-entrypoint-initdb.d: empty section between colons
* error decoding 'Volumes[1]': invalid spec: db_data:: empty section between colons
* error decoding 'Volumes[2]': invalid spec: db_logs:: empty section between colons
Is there a way in docker stacks to specify to look for those volumes locally to the worker node
? also for .env
files ?
Here is my docker-stack.yaml
:
version: "3.8"
services:
nginx:
container_name: nginx
image: "${NGINX_IMAGE}"
build: build/nginx
deploy:
placement:
constraints: [node.role == manager]
restart: always
env_file: .env
ports:
- "80:80"
- "443:443"
volumes:
- "${APP_HOST_DIR}/public:/var/www/app/public:ro"
- "${APP_HOST_LETSENCRYPT}:${APP_CONTAINER_LETSENCRYPT}"
- "${APP_HOST_NGINX_CONF}:${APP_CONTAINER_NGINX_CONF}"
networks:
- central_mr
depends_on:
- app
container_name: app
image: "${APP_IMAGE}"
deploy:
placement:
constraints: [node.role == manager]
restart: always
build: build/app
env_file: .env
networks:
- central_mr
volumes:
- "${APP_HOST_DIR}:${APP_CONTAINER_DIR}"
dbmr:
container_name: database
image: "${MARIADB_VERSION}"
restart: always
deploy:
placement:
constraints: [node.role == worker]
env_file: .env
volumes:
- "${SQL_INIT}:/docker-entrypoint-initdb.d"
- "db_data:${MARIADB_DATA_DIR}"
- "db_logs:${MARIADB_LOG_DIR}"
environment:
MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
MYSQL_DATABASE: "${MYSQL_DATABASE}"
MYSQL_USER: "${MYSQL_USER}"
MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
ports:
- "3306:3306"
networks:
- central_mr
volumes:
db_data:
db_logs:
networks:
central_mr:
–
–
–
–
the .env is on the worker node; I have a different .env on my manager. I need the service to look for .env on the machine it is running onto. Same for volumes
This isn't supported. First, I'm not sure the .env
file will be parsed (it wasn't last time I checked). So to expand variables inside of the compose file, you need to source those variables yourself where you run the stack deploy command:
set -a; . ./.env; set +a
docker stack deploy -c docker-compose.yml stack_name
That does not expand the values from the files on the workers. There will only be one state for the service and containers deployed on workers, with one exception.
A few of the fields support service templates which allow you to set fields like an env variable or volume mount, using templates like {{.Node.Hostname}}
.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.