2017-07-07 47 views
1

我见过泊坞量docker-compose.yml文件,像这样的定义:泊坞窗匿名Voumes

-v /path/on/host/modules:/var/www/html/modules 

我注意到Drupal's official image,他们docker-compose.yml文件是使用anonymous volumes

公告点评:

volumes: 
    - /var/www/html/modules 
    - /var/www/html/profiles 
    - /var/www/html/themes 
    # this takes advantage of the feature in Docker that a new anonymous 
    # volume (which is what we're creating here) will be initialized with the 
    # existing content of the image at the same location 
    - /var/www/html/sites 

有没有一种方法,容器运行后,一位不愿意透露姓名的体积与主机上的路径相关联?如果不是,拥有匿名卷有什么意义?

全搬运工-compose.yml例如:

version: '3.1' 

services: 

    drupal: 
    image: drupal:8.2-apache 
    ports: 
     - 8080:80 
    volumes: 
     - /var/www/html/modules 
     - /var/www/html/profiles 
     - /var/www/html/themes 
     # this takes advantage of the feature in Docker that a new anonymous 
     # volume (which is what we're creating here) will be initialized with the 
     # existing content of the image at the same location 
     - /var/www/html/sites 
    restart: always 

    postgres: 
    image: postgres:9.6 
    environment: 
     POSTGRES_PASSWORD: example 
    restart: always 

回答

1

匿名卷等效具有在图像的Dockerfile定义为卷的这些目录。事实上,在Dockerfile 中定义为VOLUME的目录是匿名卷,如果它们没有明确映射到主机。

拥有它们的一点是增加了灵活性。

PD: 匿名卷已经驻留在/ var/lib/docker(或您配置的任何目录)的某处。要看到,他们是:

docker inspect --type container -f '{{range $i, $v := .Mounts }}{{printf "%v\n" $v}}{{end}}' $CONTAINER

注:替换$CONTAINER与容器的名字。