[英]How can I overwrite a file through Dockerfile in docker container?
I have to overwrite a file through Dockerfile. 我必须通过Dockerfile覆盖一个文件。 In particular on an Ubuntu container with Apache and PHP and I have to overwrite the file php5-cgi.conf.
特别是在使用Apache和PHP的Ubuntu容器上,我必须覆盖php5-cgi.conf文件。 I tried to use the following command:
我尝试使用以下命令:
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/
but the file is not copied when the container is running, Is there any advice on this? 但是当容器运行时不会复制文件,对此有任何建议吗?
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. 目标是绝对路径 (不是文件名),或相对于工作目录的路径,源将在目标容器中复制到该路径中。
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_version
in the same folder as dockerfile
or use absolute path
. 作为PolarisUser在注释中规定,你需要把
debian_version
在同一文件夹作为dockerfile
或使用absolute path
。 Another way would be mounting the file when running the container. 另一种方法是在运行容器时挂载文件。
docker run -d -v php5-cgi.conf:/etc/apache2/conf-enabled/php5-cgi.conf --name your_container_name <imagename:tag> <startup command>
docker cp "yourfilename" "containername":/destination
以下是一个工作示例:
docker cp config.json bigdataapp:/app/src/bigdatapp/wwwroot/assets/config/config.json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.