2017-07-07 6 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に置き換えてください。