Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

306
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda