6

I need to reduce my Docker image size so I need to run all copy files command to single shell command This is my Docker file copy command

COPY rdkafka.ini /etc/php/7.0/mods-available/
COPY 20-rdkafka.ini /etc/php/7.0/apache2/conf.d/
COPY apache2.conf /etc/apache2/
COPY php.ini /etc/php/7.0/apache2/

Into single command

RUN cp rdkafka.ini /etc/php/7.0/mods-available/ && cp 20-rdkafka.ini /etc/php/7.0/apache2/conf.d/ && apache2.conf /etc/apache2/ && php.ini /etc/php/7.0/apache2/

I am getting this error

cp: cannot stat 'rdkafka.ini': No such file or directory

Any help?

Sujan Kumar Sakthi
  • 403
  • 1
  • 5
  • 10

1 Answers1

7

This is because RUN cp ... is not the same as COPY. COPY copies files from your host machine to the image, RUN runs inside the container during it's build process, and fails because there really is "No such file or directory" in there.

And looking at the COPY documentation, there really is not a way to copy multiple files to multiple destinations with one COPY, only multiple sources to one destination.

What you probably can do, if you really want, is to COPY everything first to one directory, for example /tmp, and then use the RUN cp /tmp/rdkafka.ini /etc/php/7.0/mods-available/ && ....

Teemu Risikko
  • 1,205
  • 11
  • 16