Docker compose yml文檔結(jié)構(gòu)

介紹

  • Compose是用于定義和運(yùn)行多容器Docker應(yīng)用程序的工具。
  • 通過(guò)Compose,您可以使用YAML文件來(lái)配置應(yīng)用程序的服務(wù)。
  • 使用一個(gè)命令,就可以從配置中創(chuàng)建并啟動(dòng)所有服務(wù)
  • Compose可在所有環(huán)境中工作:生產(chǎn),登臺(tái),開(kāi)發(fā),測(cè)試以及CI工作流

compose 使用步驟:

  • 使用定義您的應(yīng)用環(huán)境,Dockerfile以便可以在任何地方復(fù)制它。

  • 定義組成應(yīng)用程序的服務(wù),docker-compose.yml 以便它們可以在隔離的環(huán)境中一起運(yùn)行。

  • Run docker-compose upand Compose啟動(dòng)并運(yùn)行您的整個(gè)應(yīng)用程序。

安裝

mac os 默認(rèn)安裝

測(cè)試

> docker-compose --version
docker-compose version 1.24.1, build 4667896b

docker compose yaml結(jié)構(gòu)

version: "3.7"
services:
 webapp:
   image: webapp:tag
   cap_add:
     - ALL
   cap_drop:
     - NET_ADMIN
     - SYS_ADMIN
   cgroup_parent: m-executor-abcd
   command: bundle exec thin -p 3000
   container_name: my-web-container
   credential_spec:
     config: my_credential_spec
   build:
     context: ./dir  # 相對(duì)于yml文件 
     dockerfile: Dockerfile-alternate
     depends_on:
       - db
       - redis
     args:
       buildno: 1  # - buildno=1 也可以 ,需要dockerfile 定義ARG buildno 
     cache_from:
       - alpine:latest
       - corp/web_app:3.14
     labels:
       com.example.description: "Accounting webapp"
       com.example.department: "Finance"
       com.example.label-with-empty-value: ""
     shm_size: '2gb'   # shm_size: 10000000 也可以
   deploy:
     replicas: 1
   devices:
     - "/dev/ttyUSB0:/dev/ttyUSB0"
   dns: 8.8.8.8
   dns_search: example.com
   entrypoint: /code/entrypoint.sh
   env_file:
     - ./common.env
     - ./apps/web.env
     - /opt/secrets.env 
   environment:
     RACK_ENV: development
     SHOW: 'true'
     SESSION_SECRET: 
   expose:
    - "3000"
    - "8000"
   external_links:
    - redis_1
    - project_db_1:mysql
    - project_db_1:postgresql
   extra_hosts:
    - "somehost:162.242.195.82"
    - "otherhost:50.31.209.229"
   links:
    - db
    - db:database
    - redis
   logging:
     driver: syslog
     options:
       syslog-address: "tcp://192.168.0.42:123"
   ports:
      - "3000"
      - "3000-3005"
      - "8000:8000"
      - "9090-9091:8080-8081"
      - "49100:22"
      - "127.0.0.1:8001:8001"
      - "127.0.0.1:5000-5010:5000-5010"
      - "6060:6060/udp"
   restart: on-failure
   stop_signal: SIGUSR1
   ulimits:
     nproc: 65535
     nofile:
       soft: 20000
       hard: 40000
   configs:
     - source: my_config
       target: /redis_config
       uid: '103'
       gid: '103'
       mode: 0440
 redis:
   image: redis
 db:
   image: postgres
configs:
 my_config:
   file: ./my_config.txt
 my_other_config:
   external: true
 my_credentials_spec:
   file: ./my-credential-spec.json|

參考文獻(xiàn)

本文作者:前端首席體驗(yàn)師(CheongHu)
聯(lián)系郵箱:simple2012hcz@126.com
版權(quán)聲明: 本文章除特別聲明外,均采用 CC BY-NC-SA 4.0 許可協(xié)議。轉(zhuǎn)載請(qǐng)注明出處!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容