Compos file 版本3以上
Compos file v3官网
只支持单机运行
1 2 3 4 5 6 7 8
| version: "3" services: webapp: build: context: ./dir dockerfile: Dockerfile-alternate args: buildno: 1
|
只支持集群模式运行,只需要在单机上引用,会自动在其他节点创建配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| version: "3.3" services: redis: image: redis:latest deploy: replicas: 1 configs: - my_config - my_other_config configs: my_config: file: ./my_config.txt my_other_config: external: true
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| version: '3' services: nginx: image: harbor.hcytech.dev/library/web-gate-id-v3:S3.2.1 restart: unless-stopped ports: - "88:80"
configs: - source: nginx_config target: /etc/nginx/conf.d/default.conf env_file: - ./config/nginx.env configs: nginx_config: file: ./config/default.conf
|
会覆盖dockerfile里面的命令例如:
1 2
| command: bundle exec thin -p 3000 command: ["bundle", "exec", "thin", "-p", "3000"]
|
deploy(swarm模式)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| version: '3.2' services: redis: image: redis:alpine labels: com.example.description: " containers 上的标签" deploy: mode: global replicas: 6 update_config: parallelism: 2 delay: 10s restart_policy: condition: on-failure endpoint_mode: vip labels: com.example.description: "This label will appear on the web service" placement: constraints: - node.role == manager - engine.labels.operatingsystem == ubuntu 14.04 preferences: - spread: node.labels.zone resources: limits:
cpus: '0.50' memory: 50M reservations: cpus: '0.25' memory: 20M restart_policy: condition: on-failure delay: 5s max_attempts: 3 window: 120s update_config: parallelism: 2 delay: 10s order: stop-first depends_on: - db - redis healthcheck: test: ["CMD", "curl", "-f", "http://localhost"] interval: 1m30s timeout: 10s retries: 3 start_period: 40s logging: driver: syslog options: syslog-address: "tcp://192.168.0.42:123" volumes: - type: volume source: mydata target: /data volume: nocopy: true - type: bind source: ./static target: /opt/app/static ports: - target: 80 published: 8080 protocol: tcp mode: host
|
问题
错误services.nginx.ports.0 must be a string or number
是因为自定义端口,只支持3.2以上
1 2 3 4 5 6
| version: '3.2' ports: - target: 80 published: 8080 protocol: tcp mode: host
|