Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 218
Ciro Caiazzo Avatar asked Nov 30 '16 18:11

Ciro Caiazzo


People also ask

Does Dockerfile copy overwrite files?

It seems that docker build won't overwrite a file it has previously copied. I have a dockerfile with several copy instructions, and files touched in earlier COPY directives don't get overwritten by later ones. After building this, $BASE/config/thatfile. yml contains the contents of file1.

Can we override CMD in Dockerfile?

An essential feature of a CMD command is its ability to be overridden. This allows users to execute commands through the CLI to override CMD instructions within a Dockerfile. A Docker CMD instruction can be written in both Shell and Exec forms as: Exec form: CMD [“executable”, “parameter1”, “parameter2”]


1 Answers

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.

like image 126
Jay Blanchard Avatar answered Sep 24 '22 03:09

Jay Blanchard