【发布时间】:2020-08-26 11:09:50
【问题描述】:
我想在 Docker 映像中包含从 python manage.py collectstatic 生成的静态文件。
为此,我在Dockerfile 中添加了以下行
CMD python manage.py collectstatic --no-input
但由于它在中间容器中运行命令,因此生成的静态文件不存在 STATIC_ROOT 目录。我可以在构建日志中看到以下几行。
Step 13/14 : CMD python manage.py collectstatic --no-input
---> Running in 8ea5efada461
Removing intermediate container 8ea5efada461
---> 67aef71cc7b6
我想在图像中包含生成的静态文件。我该怎么做才能做到这一点?
更新(解决方案)
我使用的是 CMD,但我应该使用 RUN 命令来执行此任务,就像文档说的那样
The RUN instruction will execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile.
【问题讨论】:
标签: django docker dockerfile django-staticfiles