Copying files to a container with Docker Compose Ask Question

Copying files to a container with Docker Compose Ask Question

I have a Dockerfile where I copy an existing directory (with content) to the container which works fine:

Dockerfile

FROM php:7.0-apache
COPY Frontend/ /var/www/html/aw3somevideo/
COPY Frontend/ /var/www/html/

RUN ls -al /var/www/html
RUN chown -R www-data:www-data /var/www/html 
RUN chmod -R 755 /var/www/html 

docker exec によるディレクトリ一覧のスクリーンショット

But when I use a docker-compose.yml file there is only the directory aw3somevideo and inside aw3somevideo there is nothing.

docker-compose.yml:

 php:
    build: php/
    volumes:
      - ./Frontend/ :/var/www/html/
      - ./Frontend/index.php :/var/www/html/
    ports:
      - 8100:80

空のディレクトリリストのスクリーンショット

Maybe I do not understand the function of volumes and if that's the case please tell me how to copy my existing files to the container via a docker-compose.yml file.

ベストアンサー1

Given

    volumes:
      - /dir/on/host:/var/www/html

が存在しない場合は/dir/on/host、ホスト上に作成され、空のコンテンツがコンテナーにマウントされます/var/www/html。ボリュームをアンマウントするまで、コンテナー内に以前あったコンテンツ/var/www/htmlにはアクセスできません。新しいマウントによって古いコンテンツが隠されます。

おすすめ記事