简体   繁体   English

docker 挂载卷,但将文件保留在 docker 容器内

[英]docker mount volumns but keep files inside the docker container

I use Dockerfile to build an image of php, but as the default, PHP don't have a php.ini file.我使用 Dockerfile 来构建 php 的映像,但默认情况下,PHP 没有 ZE13BFD7623E8419 文件。 So I need to create it.所以我需要创建它。 Now I have three ways to do this:现在我有三种方法可以做到这一点:

  1. use RUN command in Dockerfile RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini .在 Dockerfile RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini中使用 RUN 命令。 But this way still use a default setting, I can't edit it (or edit it and commit container).但是这种方式仍然使用默认设置,我无法编辑它(或编辑它并提交容器)。

  2. use COPY command in Dockerfile COPY php.ini /usr/local/etc/php/php.ini .在 Dockerfile COPY php.ini /usr/local/etc/php/php.ini中使用 COPY 命令。 OK, now I can edit the config and then build image, but if I need to change some setting, I need rebuild image好的,现在我可以编辑配置然后构建映像,但是如果我需要更改某些设置,我需要重建映像

  3. use volumn args, add this in docker-compose.yml - $PWD/php/conf.d:/usr/local/etc/php/conf.d/my_config .使用卷参数,将其添加到 docker-compose.yml - $PWD/php/conf.d:/usr/local/etc/php/conf.d/my_config By this way, I can edit php.ini anytime and just reload config file.通过这种方式,我可以随时编辑 php.ini 并重新加载配置文件。 But, the best way I wonder is - $PWD/php/conf.d:/usr/local/etc/php/conf.d .但是,我想知道的最好方法是- $PWD/php/conf.d:/usr/local/etc/php/conf.d the first way will create a new sub folder in docker container, the second way will delete the *.ini file that originally in the folder第一种方法将在 docker 容器中创建一个新的子文件夹,第二种方法将删除文件夹中原来的 *.ini 文件

I want to know is here some way that could mount volumn and don't delete the file in container (the second way of 3 but don't delete file)我想知道这里有某种方式可以挂载卷而不删除容器中的文件(3的第二种方式但不删除文件)

Actually the files are not deleted from the subfolder.实际上文件并没有从子文件夹中deleted The volume is mounted over it.卷安装在它上面。

Reference参考

What you can do is, assign a separate folder for your *.ini files, and reference it from the main php.ini file.您可以做的是,为您的*.ini文件分配一个单独的文件夹,并从主php.ini文件中引用它。 So every time you reload php, it goes to php.ini and from there it gets your dedicated config folder and loads all the *.ini files from there.因此,每次重新加载 php 时,它都会转到php.ini并从那里获取您的专用配置文件夹并从那里加载所有*.ini文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM