Skip to content

Elastic Beanstalk Docker Platform is not serving static files in real time.

0

My django application is deployed on docker-compose on elastic beanstalk. I use my own nginx container for static files. The problem is that the whole workflow works well on simple EC2 instances but on EBS it takes time to update static files, the static files take time to change maybe after deploying new deployments time to time. For example: today I ran 5 builds and the changes in static files in my first build will come after the 5th build. The other changes reflect instantly. I even added docker prune commands in prebuild in hooks, they run successfully but nothing changes.

I also applied this method - https://stackoverflow.com/questions/50113686/serving-django-static-files-in-elasticbeanstalk-docker-environment - first answer

Please help!!!

asked 2 years ago538 views
1 Answer
6
Accepted Answer

Hello,

Enable Cache Busting: Use ManifestStaticFilesStorage in your settings.py to append a version or hash to static file URLs:

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'

Check Nginx Caching: Ensure your Nginx configuration properly handles caching

location /static/ {
    expires max;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

Update Docker Config: Make sure Docker removes old images and volumes:

docker system prune -af

CloudFront Invalidation: If using CloudFront, invalidate the cache after deployments:

aws cloudfront create-invalidation --distribution-id YOUR_DISTRIBUTION_ID --paths "/*"

Docker Volume Mounts:

Verify volume mounts: Double-check your docker-compose.yml file to ensure static files are mounted as volumes from your Django container to the Nginx container. This ensures changes in the Django container reflect in Nginx.

Elastic Beanstalk Caching:

Disable EBS caching: While less likely in your case, EBS might be caching deployments. This can be disabled in the Elastic Beanstalk configuration under "Software and platform updates" -> "Environment updates" -> "Deployment policy" -> "Discard caches before each deployment".

EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
EXPERT
reviewed 2 years ago
  • Can you exaggerate more on the first step. I wanna apply that solution.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.