2

What I have

I have a container with Django app that executes a Celery task whose purpose is to delete some files that are the media folder, that container is called backend in docker-compose.yml.

Problem

the problem is that the Celery Worker and Celery beat container runs normally and execute the task but does not delete media files. it may be that the problem lies in the volumes mounted on the containers and somehow Celery does not find the media files to be deleted.

docker-compose.yml

version: '3.8'
services:
 # Django app that will upload the files from the admin and that will be deleted by the Celery task.
 backend:
 expose:
 - 8000
 build:
 context: .
 dockerfile: ./Dockerfile
 networks:
 - backend-tier
 depends_on:
 - db
 redis:
 image: library/redis:5.0-alpine
 ports:
 - 6379:6379
 restart: unless-stopped
 networks:
 - backend-tier
 volumes:
 - valor-redis:/data
 worker:
 build:
 context: .
 dockerfile: ./Dockerfile
 command: celery -A config --app=config.celery_app:app worker --loglevel=info
 restart: unless-stopped
 networks:
 - backend-tier
 depends_on:
 - redis
 volumes:
 - ./app_com_co/:/app/app_com_co:Z,cached
 - ./app_com_co/templates/:/app/app_com_co/templates:Z,cached
 # shared volume between worker and backend for media
 - app-media:/app/app_com_co/media
 
 beat:
 build:
 context: .
 dockerfile: ./Dockerfile
 command: celery -A config --app=config.celery_app:app beat --loglevel=info
 restart: unless-stopped
 networks:
 - backend-tier
 depends_on:
 - redis
 volumes:
 - ./app_com_co/:/app/app_com_co:Z,cached
 - ./app_com_co/templates/:/app/app_com_co/templates:Z,cached
 # shared volume between beat and backend for media
 - app-media:/app/app_com_co/media
volumes:
 app-redis:
 driver: local
 app-media:
networks:
 backend-tier:
 driver: bridge
asked Dec 29, 2020 at 22:13
5
  • how do those media files should get there in the first place? uploaded from backend container? Commented Dec 30, 2020 at 10:51
  • @ItayB Yes, its uploaded from backend container (from the Django admin)... . The Celery task will check every day and find the files that are at a certain date and delete them. Commented Dec 30, 2020 at 14:34
  • 1
    so why didn't you add the app-media volume to the backend container as well? Commented Dec 30, 2020 at 15:35
  • you're right, the app-media volume needed to be added to backend to delete the files. one additional question, what kind of volume to apply a named shared volume or a Host volume fit better for this case. Commented Dec 31, 2020 at 16:03
  • not sure what you are asking, can you elaborate? and I added my answer, if it solves your question please accept that :) Commented Dec 31, 2020 at 17:12

1 Answer 1

2

You're missing the app-media volume that needed to be added to backend if the files are uploaded there.

answered Dec 31, 2020 at 17:11
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.