簡體   English   中英

為什么我們需要服務中的卷和 docker 組合文件中的卷

[英]Why we need volumes inside services and volumes in docker compose file

我想了解為什么我們在 docker 中的服務內部有volumes ,請在同一個文件中編寫文件和服務外部的volumes 我們不能只用一個嗎?

下面是使用 postgres 數據庫構建的 durpal 內容管理系統:

version: '2'

services:
  durpal:
    image: durpal
    ports:
      - '8080:80'
    volumes:
      - drupal-modules:/var/www/html/modules
      - drupal-profiles:/var/www/html/profiles
      - drupal-sites:/var/www/html/sites
      - drupal-themes:/var/www/html/themes
  postgres:
    image: postgres
    environment:
      - POSTGRES_PASSWORD = mypasswd
volumes:
  - drupal-modules:
  - drupal-profiles:
  - drupal-sites:
  - drupal-themes:

請參閱官方文檔:使用volumes頂級元素定義要在docker-compose.yml中使用的命名卷。

另一方面,使用volumes服務屬性,您可以指定在該容器中安裝卷的位置,並引用頂級元素中定義的命名卷。

您(可以)將卷的定義留空的原因是,為省略的詳細信息分配的默認值在大多數情況下已經是您想要的。 因此,僅指定卷的名稱就足以讓它們使用默認配置創建。 查看volumes頂級元素文檔以了解可用的其他配置。

要了解有關卷的更多信息,請參閱文檔中的此頁面

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM