首页 > 解决方案 > Docker - unable to copy file after downloading due to intermediate container gets removed

问题描述

I have a larger docker file involving a lot of steps (it's single stage however) at the very end of the docker file I am trying to download a configuration file and then copy it to a specific path and run the program.

EXPOSE 830

RUN wget https://myurl/supervisord.conf

COPY supervisord.conf /etc/supervisord.conf

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

However, it seems like when the file get's downloaded successfully the intermediate docker container gets removed an another interim container gets created, and because of that it gives an error saying it can not find the configuration file.

How to avoid this situation? I have also tried using the --rm=true flag when building the docker file to avoid deleting the intermediate container and that did not solve the problem.

enter image description here

标签: docker

解决方案


You can directly put the file at /etc/supervisord.conf using -O with wget -

RUN wget https://myurl/supervisord.conf -O /etc/supervisord.conf

In case you do not want this to be done by wget, you can do a normal cp -

RUN cp supervisord.conf /etc/supervisord.conf

COPY statement in Dockerfile is basically used to copy contents from host to the relevant docker image layer or the container that you want to create. Your COPY is supposed to fail because supervisord.conf doesn't exist on your host.


推荐阅读