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

303
Views
Docker no está guardando archivos multimedia de django en el directorio 'media' del proyecto en producción

Descripción de la aplicación


Tengo una aplicación con django-gunicorn para back-end y reactjs-nginx con front-end, todo en contenedores y alojado en la instancia aws ec2.

Problema


En el entorno de desarrollo, los archivos multimedia se guardan en el directorio 'media' de forma permanente. Sin embargo, esos archivos solo se guardan en el contenedor docker actual en ejecución en tiempo de producción. Como resultado, los archivos se eliminarán cuando reconstruya/detenga el contenedor para una nueva inserción de código.

Expectativa


Quería almacenar el archivo en la carpeta 'media' para uso permanente.

Código importante


configuración.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-producción.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

Finalmente me di cuenta del problema. Olvidé agregar .:/code a mi configuración de volúmenes nginx en mi archivo docker-compose. gracias a esta respuesta

Volúmenes nginx actualizados 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!