7

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?

1 Answer 1

8

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/ && ....

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Teemu. I will try your suggestion
@teemu-risikko tried the same but no luck. I'm getting error cp: cannot stat No such file or directory. I first copied all the files and then running cp in RUN.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.