A
A
Alexander Bondarenko2021-11-12 12:00:29
Django
Alexander Bondarenko, 2021-11-12 12:00:29

How to get a file on nginx from another container?

Hello everyone, I have a site on docker, NGINX + DJANGO + POSTGRESQL + CELERY. I store text files in the database, I have them on the nginx container, and I cannot get them when I try to open the file:

def read_members(group):
    group = get_object_or_404(UserGroup, id=group)
    print(group.members.path)
    with open(group.members.path, mode='r', encoding='UTF-8', errors='strict', buffering=1) as file:
        members = file.readlines()

I am getting an error:
FileNotFoundError: [Errno 2] No such file or directory: '/var/www/site/media/activities/user_group/users.txt'


docker-compose

version: '3'

services:

  backend:
    build: ./
    container_name: site_container
    restart: always
    command: ./commands/start_server_${MODE}.sh
    ports:
      - "${PORT}:${WSGI_PORT}"
    volumes:
      - .\src:/srv/project/src
      - .\commands:/srv/project/commands
      - .\src\media:/srv/project/media
      - static_content:/var/www/site
    env_file:
      - .env
    environment:
      - DJANGO_SETTINGS_MODULE=app.settings.${MODE}
    depends_on:
      - postgres

  postgres:
    image: postgres:12
#    environment:
#      - POSTGRES_PASSWORD=mysecretpassword
    volumes:
      - pg_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    env_file:
      - .env

  nginx:
    image: nginx:1.19
    volumes:
      - .\nginx:/etc/nginx/conf.d
      - static_content:/var/www/site
    ports:
      - 80:80
      - 443:443
    env_file:
      - .env
    depends_on:
      - backend

  rabbitmq:
    image: rabbitmq:3.8-management-alpine
#    ports:
#      - 8181:15672
    env_file: .env
    restart: always

  redis:
    image: redis
    env_file: .env
    restart: always

  redis-commander:
    container_name: redis-commander
    hostname: redis-commander
    image: rediscommander/redis-commander:latest
    restart: always
    environment:
    - REDIS_HOSTS=redis
    ports:
    - "8081:8081"

  celery:
    env_file: .env
    build: .
    command: ./commands/start_celery.sh
    restart: always
    depends_on:
      - redis
      - rabbitmq
    environment:
      - DJANGO_SETTINGS_MODULE=app.settings.${MODE}
    volumes:
      - ./src:/srv/project/src
      - ./commands:/srv/project/commands

  celerybeat:
    env_file: .env
    build: .
    container_name: celerybeat
    command: ./commands/start_celerybeat.sh
    restart: always
    depends_on:
      - redis
      - celery
      - rabbitmq
    environment:
      - DJANGO_SETTINGS_MODULE=app.settings.${MODE}
    volumes:
      - ./src:/srv/project/src
      - ./commands:/srv/project/commands


volumes:
  pg_data: {}
  static_content: {}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-11-12
@bond_1013

https://docs.docker.com/storage/volumes/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question