dockerized Web应用程序商店应该在哪里上传文件?

时间:2016-03-19 15:47:07

标签: file-upload docker

我正在构建一个需要允许用户上传个人资料图片的网络应用程序。我希望应用程序是自包含的,以便人们不需要拥有s3或其他云存储服务帐户。

最好将docker容器尽可能保持一次性使用,所以我想我应该创建一个卷。所以我希望自动创建卷,这样人们在运行容器时就不必指定卷,但是dockerfiles中VOLUME指令的文档让我感到困惑。

  

VOLUME指令创建一个具有指定名称的安装点,将其标记为从本机主机或其他容器保存外部安装的卷。

被标记为什么意味着什么?数据由应用程序编写,它不是来自扩展源。

2 个答案:

答案 0 :(得分:2)

您不会遇到问题,图像将毫无问题地上传到已安装的文件系统。

也许您必须为uploads文件夹指定免费权限,以便您可以在其上书写。

答案 1 :(得分:2)

当你在dockerfile中标记一个卷时,比如说Thread 0 is created Thread 1 is created Thread 2 is created Thread 3 is created Thread 4 is created Thread 5 is created Thread 6 is created Thread 7 is created Thread 8 is created Thread 9 is created Thread 10 is created Thread 11 is created Thread 12 is created Thread 13 is created Thread 14 is created Thread 15 is created Thread 16 is created Thread 17 is created Thread 18 is created Thread 19 is created Thread 20 is created Thread 16 waiting | Threads waiting: 1 Thread 9 waiting | Threads waiting: 2 Thread 5 waiting | Threads waiting: 3 Thread 14 waiting | Threads waiting: 4 Thread 0 waiting | Threads waiting: 5 Thread 13 waiting | Threads waiting: 6 Thread 15 passed | Threads waiting: 6 Thread 10 passed | Threads waiting: 6 Thread 4 passed | Threads waiting: 6 Thread 12 passed | Threads waiting: 6 Thread 1 passed | Threads waiting: 6 Thread 20 passed | Threads waiting: 6 Thread 11 passed | Threads waiting: 6 Thread 18 passed | Threads waiting: 6 Thread 3 passed | Threads waiting: 6 Thread 2 passed | Threads waiting: 6 Thread 17 passed | Threads waiting: 6 Thread 8 passed | Threads waiting: 6 Thread 6 passed | Threads waiting: 6 Thread 19 passed | Threads waiting: 6 Thread 7 passed | Threads waiting: 6 ,这样就可以很容易地在以后运行另一个容器VOLUME /site/uploads并且在新容器中有--volumes-from <container-name>可用的所有容器已写入和将要写入的数据(如果第一个容器仍在运行)。

此外,第一次启动容器后,您将能够以/site/uploads看到该卷。

如果删除容器,您可能遇到的唯一问题是,您将丢失docker volume ls提供的映射,告知您容器创建的卷。要清楚快速地查看容器创建的卷,如果安装了docker inspect <container-name>,请尝试docker inspect <container-name> | jq '.[].Mounts'。否则,当您只有一个卷时,jq可能就足够了。 (你也可以自己趟过所有的json)

即使您删除了创建该卷的容器,该卷仍会保留在您的系统上,只有docker inspect <container-name> | grep Mounts -A 10才能查看,除非您运行docker volume ls

注意:我使用的是docker版本1.10.3