Home > Back-end >  Set default media files in Docker using Django
Set default media files in Docker using Django

Time:08-18

I am deploying my Django web application using Docker and Docker Compose, Nginx and Postgresql. I have already done the deployment and it works well. But I have a problem with the default media files.

When I was deploying in local and in my server, I add those default media files manually to the media folder, but now with Docker I can't do that.

One of my models would be that one, which has a default image "dictionary/default.png" and obviously when I run my docker image doesn't load because it doesn't exist anywhere.

class Dictionary(models.Model):

      dictionary_name = models.CharField(max_length=200)
      dictionary_picture = models.ImageField(upload_to='dictionary', default='dictionary/default.png')

I was thinking to have these default media files locally and copy them to the Docker media folder in the Dockerfile, but I do not know if this is possible.

CodePudding user response:

There is a COPY instruction in the Dockerfile.

For example, copy all files from the dictionary to the media:

...
COPY dictionary/ /app/media/
...

If you already set WORKDIR /app:

...
COPY dictionary/ ./media/
...
  • Related