Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

305
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda