I want to add a volume to my service, but only if the final user gave a folder for it. Otherwise, no volume should be mounted, for the already-prepared image has valid data in a
We can use conditional statement in docker-compose.yml file as below:
#jinja2: lstrip_blocks: True
version: "3.2"
services:
app-name:
image: url
deploy:
replicas: {{replication-num}}
resources:
limits:
memory: 4G
reservations:
memory: 1G
restart_policy:
condition: any
max_attempts: 3
update_config:
delay: 60s
failure_action: rollback
parallelism: 1
monitor: 30s
placement:
constraints:
- node.labels.node == worker
ports:
- "{{url}}:8000"
environment:
ps_environment: "{{env}}"
{% if env=='sandbox' %}
extra_hosts:
- {{ sandbox_fully }}
{% endif %}
secrets:
- source: pwdFile
labels:
- container_name=app-name
networks:
- App_External_Overlay
volumes:
- {{ dir }}:{{ dir }}