在docker内部运行的web应用程序中创建的目录丢失

2024-04-25 22:08:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经创建了一个web应用程序,使用部署在docker中的Django和Flask上传图像文件。但是,我创建的用于存储上载文件的目录在我的容器中丢失。你知道吗

172.17.0.1 - - [19/Nov/2016 14:27:06] "GET / HTTP/1.1" 200/app/images/
[<FileStorage: u'image_7.png' ('image/png')>]
<FileStorage: u'image_7.png' ('image/png')>
image_7.png is the file name
('Accept incoming file:', u'image_7.png')
('Save it to:', u'/app/images//image_7.png')
/app/images/image_7.png
/usr/lib/python2.7/dist-packages/matplotlib/font_manager.py:273:     
UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
(149, 250, 4)

在上面的日志文件中,您可以看到/app/images/它是我的应用程序创建的目录,我在其中存储上传的图像。你知道吗

我用来上传的python代码:

        target = os.path.join(APP_ROOT, 'images/')
        print(target)
        if not os.path.isdir(target):
                os.mkdir(target)
        else:
            print("Couldn't create upload directory: {}".format(target))
        print(request.files.getlist("file"))
        for upload in request.files.getlist("file"):
            print(upload)
            print("{} is the file name".format(upload.filename))
            filename = upload.filename
            destination = "/".join([target, filename])
            print ("Accept incoming file:", filename)
            print ("Save it to:", destination)
            upload.save(destination)

这是我的Dockerfile结构:

  ├── Dockerfile
  ├── app
  │   ├── app.py
  │   ├── index.csv
  │   ├── pyimagesearch
  │   │   ├── __init__.py
  │   │   ├── colordescriptor.py
  │   │   └── searcher.py
  |   ├── **images**(this folder is missing) 
  │   ├── static
  │   │   ├── main.css
  │   │   └── main.js
  │   └── templates
  │       ├── _base.html
  │       └── index.html
  ├── config
  │   ├── app.ini
  │   ├── nginx.conf
  │   └── supervisor.conf
  └── requirements.txt

谁能告诉我,如何使这个图像目录和存储在其中的文件可见?你知道吗

注意:如果我在没有docker的情况下运行这个应用程序,那么图像目录是可见的。你知道吗


Tags: 文件thepyimage目录app应用程序target