Docker-compose, conditional statements? (e.g. add volume only if condition)

后端 未结 6 1679
野趣味
野趣味 2021-02-12 02:25

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

6条回答
  •  说谎
    说谎 (楼主)
    2021-02-12 03:11

    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 }}
    

提交回复
热议问题