在Docker容器更新后将Django应用的媒体文件存储在哪里以保存它们? [英] Where to store media files of Django app in order to save them after docker container updating?

查看:74
本文介绍了在Docker容器更新后将Django应用的媒体文件存储在哪里以保存它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django应用,媒体文件正在上传到my_project_directory/media/images/(所以没什么特别的,只是一种常见的方法).在对我的应用进行docker化后出现了问题.每次在提取最新的docker镜像后需要更新容器时,都会删除旧容器(当然包括媒体文件),并构建一个新的空容器.所以问题是-如何使我的Django应用变为无状态,以及在哪里/如何存储媒体文件?是否可以将它们存储在特殊的Docker容器中?如果是,怎么办?如果没有,您有什么建议?

I have a Django app where media files are uploading to the my_project_directory/media/images/ (so nothing special, just a common approach). The problem raised after dockerizing my app. Every time i need to update my container after pulling latest docker image, old container is removed(including, of course media files) and the new, empty one is built. So the question is - how to make my Django app stateless and where/how to store media files? Is it possible to store them in a special docker container? If yes, how? if no, what could you suggest?

推荐答案

只需使用docker volumes 将持久性数据挂载到容器外部.可以在此处找到更多信息.

simply use docker volumes to mount your persistent data outside of the container. More info can be found here.

这篇关于在Docker容器更新后将Django应用的媒体文件存储在哪里以保存它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆