使用Docker Compose将文件复制到容器 [英] Copying files to a container with Docker Compose

查看:3629
本文介绍了使用Docker Compose将文件复制到容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Dockerfile,将现有目录(包含内容)复制到可以正常工作的容器中:

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-compose.yml文件时,只有目录aw3somevideo,而在aw3somevideo内部则没有任何内容.

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

也许我不理解volumes的功能,如果是这种情况,请告诉我如何通过docker-compose.yml文件将现有文件复制到容器中.

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.

推荐答案

给出

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

如果/dir/on/host不存在,则会在主机上创建它,并将空内容装入/var/www/html的容器中.容器中/var/www/html中您之前拥有的所有内容都无法访问,直到您卸载该卷为止;否则,将无法访问该内容.新的坐骑隐藏了旧内容.

if /dir/on/host doesn't exist, it is created on the host and the empty content is mounted in the container at /var/www/html. Whatever content you had before in /var/www/html inside the container is inaccessible, until you unmount the volume; the new mount is hiding the old content.

这篇关于使用Docker Compose将文件复制到容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆