How can I overwrite a file through Dockerfile in docker container?
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:
COPY php5-cgi.conf /etc/apache2/conf-enabled/php5-cgi.conf
but I had the error: 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.
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. 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
Below is a working example:
docker cp config.json bigdataapp:/app/src/bigdatapp/wwwroot/assets/config/config.json