从哪里/如何在/ var / www / html中填充文件? [英] From where/how the files get populated in /var/www/html?

查看:154
本文介绍了从哪里/如何在/ var / www / html中填充文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Docker,并试图理解。看一下 wordpress撰写及其 dockerfile 我不知道哪个命令负责填充将wordpress文件放入 / var / www / html

I am learning Docker and trying to understand volumes. Looking at this example of wordpress compose and its dockerfile I don't get which command is responsible for populating wordpress files into /var/www/html.

我确实看到dockerfile中有 VOLUME / var / www / html 命令来创建安装点。

I do see that there is VOLUME /var/www/html command in the dockerfile to create a mount point.

有命令下载wordpress文件并将其放在 / usr / src / wordpress 目录中。

There is command to download wordpress files and put in /usr/src/wordpress directory.

但是我没有得到的是文件如何进入 / var / www / html

But what I don't get is how does files get into /var/www/html?

是否只是将其挂载到该目录中会导致所有神奇地存储在其中的wordpress文件?

Is it just that mounting to this directory cause all the wordpress files magically stored in this?

是不是在其他地方,码头工人正在这样做?

Is it somewhere else docker is doing this?

编辑:这些WordPress文件在运行 docker-compose up 。我不问如何将文件移动/挂载到 / var / www / html 中。但是问题是,这是怎么回事,参考上面的dockerfile和docker compose文件。

These wordpress files are already moved or copied when ran docker-compose up. I'm not asking how can move/mount files into /var/www/html. But question is how this things happened referring to the dockerfile and docker compose file above.

谢谢

推荐答案

在这种情况下,入口点将复制文件(如果尚不存在)。请注意,在Dockerfile中,已添加wordpress源到/ usr / src / wordpress 。然后,当容器启动时,入口点检查是否存在某些文件,如果不存在,则将wordpress源复制到当前目录中,该目录为 WORKDIR ,即/ var / www / html。

In this case, the entrypoint is copying the files if they don't already exist. Note in the Dockerfile that the wordpress source is added to /usr/src/wordpress. Then, when the container starts, the entrypoint checks if some files exist and if they don't, it copies the wordpress source into the current directory, which is WORKDIR, which is /var/www/html.

使用 / var / www / html 指定为 VOLUME ,从容器的角度来看,将文件放入其中的唯一方法是将带有文件的Docker卷附加到该容器。

With /var/www/html specified as a VOLUME, the only way to get files into there from the container's perspective is to attach a docker volume with files to that. Think of it as a mountpoint.

您可以将本地文件系统附加到该卷:

You can either attach a local filesystem to that volume:

docker run -v /path/to/local/webroot:/var/www/html wordpress

,或者您可以创建一个Docker卷并将其用于持久的,更具Docker风格的对象:

or you can create a docker volume and use it for a persistent, more docker-esque object:

docker volume create webroot

然后使用临时容器将文件移入其中:

And then move the files into it with a transient container:

docker run --rm -v /path/to/local/webroot:/var/www/html \
           -v webroot:/var/www/html2 \
           ubuntu cp -a /var/www/html/ /var/www/html2

此时,您可以将 webroot 作为docker卷,可以附加到任何容器。

at which point you have webroot as a docker volume you can attach to any container.

docker run -v webroot:/var/www/html wordpress

这篇关于从哪里/如何在/ var / www / html中填充文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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