使用 Docker Compose 将文件复制到容器

编程入门 行业动态 更新时间:2024-10-17 09:52:34
本文介绍了使用 Docker Compose 将文件复制到容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Dockerfile

来自 php:7.0-apache复制前端//var/www/html/aw3somevideo/复制前端//var/www/html/运行 ls -al/var/www/html运行 chown -R www-data:www-data/var/www/html运行 chmod -R 755/var/www/html

但是当我使用 docker-compose.yml 文件时,只有目录 aw3somevideo 而在 aw3somevideo 里面什么都没有.

docker-compose.yml:

 php:构建:php/卷:- ./Frontend/:/var/www/html/- ./Frontend/index.php :/var/www/html/端口:- 8100:80

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

解决方案

Given

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

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

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.

解决方案

Given

    volumes:
      - /dir/on/host:/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屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 04:22:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/795938.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   文件   Docker   Compose

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!