php 如何通过docker容器中的Dockerfile覆盖文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40895859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:16:46  来源:igfitidea点击:

How can I overwrite a file through Dockerfile in docker container?

phpapachedockerdockerfile

提问by Ciro Caiazzo

I have to overwrite a file through Dockerfile. In particular on an Ubuntu container with Apache and PHP and I have to overwrite the file php5-cgi.conf. I tried to use the following command:

我必须通过 Dockerfile 覆盖一个文件。特别是在带有 Apache 和 PHP 的 Ubuntu 容器上,我必须覆盖文件 php5-cgi.conf。我尝试使用以下命令:

COPY php5-cgi.conf /etc/apache2/conf-enabled/php5-cgi.conf

but I had the error: File already exists

但我有错误: File already exists

I have also tried to use the following command

我也尝试使用以下命令

RUN cp -f php5-cgi.conf /etc/apache2/conf-enabled/

RUN cp -f php5-cgi.conf /etc/apache2/conf-enabled/

but the file is not copied when the container is running, Is there any advice on this?

但是在容器运行时不会复制文件,对此有什么建议吗?

回答by Jay Blanchard

Drop the file name from the destination:

从目的地删除文件名:

COPY php5-cgi.conf /etc/apache2/conf-enabled/

The destination is an absolute path(not filename), or a path relative to the work directory, into which the source will be copied inside the destination container.

目标是绝对路径(不是文件名),或相对于工作目录的路径,源将在目标容器内复制到该路径中。

回答by Farhad Farahi

I just tested following docker file with no problem.

我刚刚测试了以下 docker 文件,没有问题。

from debian:jessie
COPY debian_version /etc/debian_version

As PolarisUser stated in comments, you need to put debian_versionin the same folder as dockerfileor use absolute path. Another way would be mounting the file when running the container.

作为PolarisUser在注释中规定,你需要把debian_version在同一文件夹dockerfile或使用absolute path。另一种方法是在运行容器时挂载文件。

docker run -d -v php5-cgi.conf:/etc/apache2/conf-enabled/php5-cgi.conf --name your_container_name <imagename:tag> <startup command>

回答by Volleyball Player

docker cp "yourfilename" "containername":/destination

Below is a working example:

下面是一个工作示例:

docker cp config.json bigdataapp:/app/src/bigdatapp/wwwroot/assets/config/config.json