53

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?

VaTo
  • 2,936
  • 7
  • 38
  • 77
Ciro Caiazzo
  • 531
  • 1
  • 4
  • 3

3 Answers3

72

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.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
17

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>
Farhad Farahi
  • 35,528
  • 7
  • 73
  • 70
  • Just make sure to have debian_version in the same location that the Dockerfile is. This is the correct answer though. – PolarisUser Nov 30 '16 at 19:13
8
docker cp "yourfilename" "containername":/destination

Below is a working example:

docker cp config.json bigdataapp:/app/src/bigdatapp/wwwroot/assets/config/config.json
Eugene Berdnikov
  • 2,150
  • 2
  • 23
  • 30
Volleyball Player
  • 331
  • 1
  • 6
  • 13