【发布时间】:2017-12-12 02:15:20
【问题描述】:
我在docker-compose.yml 文件中看到了 Docker 卷定义,如下所示:
-v /path/on/host/modules:/var/www/html/modules
我注意到Drupal's official image,他们的docker-compose.yml 文件正在使用anonymous volumes。
注意 cmets:
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
有没有办法在容器运行后将匿名卷与主机上的路径相关联?如果不是,那么拥有匿名卷有什么意义?
完整的 docker-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
【问题讨论】:
标签: docker docker-compose docker-volume