M
M
mashincode2020-04-18 16:57:26
Django
mashincode, 2020-04-18 16:57:26

Where are my media and static files stored when I use docker compose?

I use docker-compose to deploy my django-nginx-gunicorn-postgres projects, despite the fact that I managed to start and configure my projects from the lessons, I still do not understand many points. For example Where are my media and static files stored when I use docker compose? When I call docker-compose -f myproject.yml run python manage.py collectstatic , I see that the files are saved in the /static directory, the same seems to happen with the media that I save in the project, but I want to be able to access the directory where in fact, /static and /media lie and it’s hard for me to understand where it is, in fact, I have a separate python code from django, which needs access to the picture that I add in the django admin panel and I don’t want to contact the server in order to to download a picture, but I want to have access to it locally, my myproject.yml

version: '3'
volumes:
  pgdata:
  static:
services:
  python:
    build:
      context: .
      dockerfile: docker/prod/python/Dockerfile
    environment:
      - DJANGO_SETTINGS_MODULE=eCommerce.settings
    volumes:
      - ./app:/app
      - static:/static
    ports:
      - 8000:8000
    command: gunicorn -w 4 eCommerce.wsgi -b 0.0.0.0:8000
  nginx:
    # image: nginx
    build:
      context: .
      dockerfile: docker/prod/nginx/Dockerfile
    volumes:
      - static:/static
    ports:
      - 80:80
      - 443:443


in settings.py, the static and media paths are written like this, usually when I start without a docker container, then all media are saved to the media folder and I can use them, how can I achieve this here?

STATIC_URL = '/static/'
STATIC_ROOT = STATIC_URL

MEDIA_URL = '/media/'
MEDIA_ROOT = MEDIA_URL

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question