docker - 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.
解决方案
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 becausesupervisord.conf
doesn't exist on your host.
推荐阅读
- ios - 使用 XCode 11.4 在模拟器中测试远程通知说不支持
- python - 熊猫多索引数据框中一列的平均值
- python - Python中的正规方程需要改进
- python - 为什么这个数组值被删除但仍然打印?
- c - MPFR 库计算精度的工作原理
- .net-core - .NET Core - 调试参数的目标
- c - 使用 ARB 扩展的 OpenGL 上下文创建不起作用
- python - Python tkinter 多个窗口
- telegram - Telegram bot(具有添加新管理员权限)无法提升新管理员或更改现有管理员的自定义标题。为什么?
- python-3.x - 如何使用请求库更改我的用户代理