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
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.
Updated April 2017
The behaviour has changed since I wrote the original answer. It is now consistent whether the right hand side specifies a named volume like
myvolume
or a path on the host like/var/lib/myapp
. For instanceif
/dir/on/host
doesn't exists, it is created on the host and the empty content is mounted in the container at/var/www/html
. Whatever was in/var/www/html
before is inaccessible.---- old answer -----------
The
volumes:
section in your docker-compose overwrites whatever is in the/var/www/html
directory.There are two mains situations:
The volume exists
In that case, the content of the volume overshadows whatever is in the dst directory.
Eg:
The volume doesn't exist
If
myvolume
doesn't exist (a named volume for instance), the content of /var/www/html will be copied to volume the first time aroundIn case 2, if you try to mount the same volume again on some container, it will follow case 1.
In that case (assuming myvolume was already created), the content of /var/ww/html will be overwritten (shadowed) by whatever is in
myvolume
.The official doc goes into more details https://docs.docker.com/compose/compose-file/#/volumes-volume-driver