[英]Maintain the media files after build with Docker Container - Django
I am using Django as a Web Framework.我正在使用 Django 作为 Web 框架。 Azure NGINEX as WebServer.
Azure NGIEX 作为 WebServer。 My Project is deployed with Docker Containers.
我的项目部署了 Docker 容器。
In my Django project root structure will be as follows:在我的 Django 项目中,根结构如下:
root:
- app1
- app2
- media
whenever saving images, it will correctly save under media folder.每当保存图像时,它都会正确保存在媒体文件夹下。 But whenever doing "docker-compose up" it will replaces the source code, so that my media folder will be cleaned up everytime.
但是每当执行“docker-compose up”时,它都会替换源代码,这样我的媒体文件夹就会每次都被清理干净。
In my settings.py file, I have added as follows:在我的 settings.py 文件中,我添加了如下内容:
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
MEDIA_URL = 'media/'
Kindly help me to maintain the media files with Docker based Environment请帮助我使用基于 Docker 的环境维护媒体文件
You have to basically do 2 things:你必须基本上做两件事:
docker-compose
configuration file to persist your media directory.docker-compose
配置文件中使用 docker 卷来保存您的媒体目录。 You can find the detailed documentation on the way to configure volumes in docker-compose
here .docker-compose
中配置卷的方式的详细文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.