Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

304
Views
Docker is not saving django media files into project 'media' directory on production

App Description


I have an app with django-gunicorn for back-end and reactjs-nginx with front-end all containerized as well as hosted on aws ec2 instance.

Problem


On development environment, media files are being saved in the 'media' directory permanently. Tho, those files are only saved on the current running docker container on production time. As a result, the files will be removed when I rebuild/stopped the container for a new code push.

Expectation


I wanted to store the file on the 'media' folder for permanent use.

Important code


settings.py

ENV_PATH = Path(__file__).resolve().parent.parent
STATIC_ROOT = BASE_DIR / 'django_static'
STATIC_URL = '/django_static/'

MEDIA_ROOT = BASE_DIR / 'media/'

MEDIA_URL = '/media/'

docker-compose-production.yml

version: "3.3"

services:
    db:
       image: postgres
       restart: always #Prevent postgres from stopping the container
        volumes:
               - ./data/db:/var/lib/postgresql/data
        environment:
                 - POSTGRES_DB=postgres
                 - POSTGRES_USER=postgres
                 - POSTGRES_PASSWORD=postgres
    ports:
        - 5432:5432

nginx:
    restart: unless-stopped
    build:
        context: .
        dockerfile: ./docker/nginx/Dockerfile
    ports:
        - 80:80
        - 443:443
    volumes:
        - static_volume:/code/backend/server/django_static
        - ./docker/nginx/production:/etc/nginx/conf.d
        - ./docker/nginx/certbot/conf:/etc/letsencrypt
        - ./docker/nginx/certbot/www:/var/www/certbot
    depends_on:
        - backend

# Volume for certificate renewal
certbot:
    image: certbot/certbot
    restart: unless-stopped
    volumes:
        - ./docker/nginx/certbot/conf:/etc/letsencrypt
        - ./docker/nginx/certbot/www:/var/www/certbot
    entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
backend:
    restart: unless-stopped
    build:
        context: .
        dockerfile: ./docker/backend/Dockerfile

    entrypoint: /code/docker/backend/wsgi-entrypoint.sh
    volumes:
        - .:/code
        - static_volume:/code/backend/server/django_static
    expose:
        - 8000
    depends_on:
        -   db

volumes:
       static_volume: { }
       pgdata: { }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I finally figured out the issue. I forgot to add .:/code to my nginx volumes config in my docker-compose file. Thank to this answer

Updated nginx volumes confi

        volumes:
        - .:/code
        - static_volume:/code/backend/server/django_static
        - ./docker/nginx/production:/etc/nginx/conf.d
        - ./docker/nginx/certbot/conf:/etc/letsencrypt
        - ./docker/nginx/certbot/www:/var/www/certbot
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!