Docker作曲家复制档案 [英] Docker composer copy files
问题描述
我有一个 Dockerfile
,我将现有的目录(含内容)复制到可正常工作的容器中:
Dockerfile
FROM php:7.0-apache
COPY前端/ / var / www / html / aw3somevideo /
COPY前端/ / var / www / html /
RUN ls -al / var / www / html
RUN chown -R www-data: www-data / var / www / html
运行chmod -R 755 / var / www / html
但是当我使用一个 docker-compose.yml
文件只有目录àw3somevideo和àw3somevideoàw3somevideo内部没有任何内容。
docker-compose .yml :
php:
build:php /
卷:
- ./Frontend/:/ var / www / html /
- ./Frontend/index.php:/ var / www / html /
港口:
- 8100:80
也许我不明白卷
的功能,如果是这样,请告诉我如何复制我现有的文件通过 docker-compose.yml
文件发送到容器。
2017年4月更新
自写了原始答案以来,行为发生了变化。现在是否一致,无论右侧是否指定一个命名卷,如 myvolume
或主机上的路径,如 / var / lib / myapp
。
例如
卷:
- / dir / on / host:/ var / www / html
如果 / dir / on / host
不存在,它在主机上创建,空的内容被挂载在 / var / www / html
的容器中。无论在 / var / www / html
之前是无法访问的。
----老答案--- --------
您的docker中的卷:
部分将覆盖任何
有两种情况:
-
卷存在
在这种情况下,卷的内容掩盖了dst中的任何内容目录。
例如:
卷:
- / dir / on / host:/ var / www / html
-
存在
如果
myvolume
不存在(例如,命名卷),则/ var / www / html将被第一次复制到卷:
- myvolume:/ var / www / html
如果您尝试挂载一些容器上的容量再次相同,则将按照案例1。
卷:
$ p在这种情况下(假设myvolume已经创建),/ var / ww / html的内容将被
- myvolume:/ var / www / html
中的任何内容覆盖(shadowed) myvolume
。
官方文档详细介绍 https://docs.docker.com/compose/compose-file/#/volumes-volume-driver
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 àw3somevideoand inside àw3somevideo
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 adocker-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 instancevolumes: - /dir/on/host:/var/www/html
if
/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:
volumes: - /dir/on/host:/var/www/html
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 aroundvolumes: - myvolume:/var/www/html
In case 2, if you try to mount the same volume again on some container, it will follow case 1.
volumes: - myvolume:/var/www/html
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
这篇关于Docker作曲家复制档案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!