Skip to content

Docker Compose Options

loging

Reduce container size of logs (support compose & swarm)

YAML
   logging:
     driver: "json-file"
     options:
       max-size: "500m"
       max-file: "10"
       compress: "true"

dns

YAML
   dns:
     - "10.0.0.2"
     - "8.8.8.8"

commnds

Fire commands inside container

YAML
   command: >
     /bin/bash -c "
     while ! nc -z cloud-config 8888; do
       echo \"Cloud-Config not available yet. Sleeping 5 sec.\";
       sleep 5;
     done;
     echo \"Connected to Cloud-Config!\";
     /usr/local/tomcat/bin/catalina.sh run
     "

ports

YAML
   ports:
     - "8080:8080

extra_hosts

YAML
   extra_hosts:
     - "sub.somedomain.com:10.0.10.30"

Labels

YAML
    labels: [app=reporting]

Container Name

Give container a name (support compose & !swarm)

YAML
    container_name: somename

Zero Downtime Deploy

YAML
    healthcheck:
      test: ["CMD", "curl", "127.0.0.1:8080/api/something"]
    deploy:
      replicas: 1
      resources:
        reservations:
          memory: 768M
        limits:
          memory: 2048M
      update_config:
        order: start-first
        failure_action: rollback
        delay: 10s
      rollback_config:
        parallelism: 0
        order: stop-first
      restart_policy:
        condition: any
        delay: 5s
        max_attempts: 3
        window: 120s

Limit Resources

YAML
      resources:
        reservations:
          memory: 2048M
          cpus: '0.0001'
        limits:
          memory: 4096M
          cpus: '0.5'
Back to top