[Django]-Django + nginx in docker containers: can not upload any file with forms

2đź‘Ť

âś…

So, you do seem to misunderstand volumes to some extent (though I don’t see anything that would cause your problem).

Volumes come from the “copy on write” filesystem that Docker uses for its images. Each layer only contains new information that hasn’t been changed since previous uses- this lets you build images in an efficient fashion without having to copy tons of data around for each container you start off of that image.

A volume is saying “do not use the copy on write filesystem for this directory”. So VOLUME ["/etc/nginx/sites-available", "/etc/nginx/certs", "/etc/nginx/conf.d"] is actually telling Docker to leave those directories OUT of the image you build. This is not what you want… I see you adding config files to your nginx configuration AFTER marking the config directory as a volume… those files changes will not propogate into the image you are building.

On to your actual problem though- I have no idea what that is. None of the deployment configuration has anything to do with “saving a file”. The only place it could is if you were trying to save it from django and then serve it back up with nginx… but you said the file isn’t getting saved, which means that nginx has nothing to do with it. I would add some debug output to your app itself to try and figure out what is going on. If it is returning a 200 without doing what it says it is (saving some file to disk)… that is where I would start.

👤Paul Becotte

2đź‘Ť

The problem was in very strange place for me.

there are model:

class Document(Model):
    name = CharField()
    file = ImageField(
                upload_to='documents/%Y/%m/',
                default='default.doc'
            )

If I delete default here, it works! But version with default work fine outside the docker.

Leave a comment