When I save a images, they are deleted automatically in a few minutes. So, I would like to know what I need to configure to keep images that are saved in the static/images folder in my Django project.
This is my dockerfile:
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN apt-get update \
&& apt-get install -y libpq-dev build-essential
RUN mkdir -p /code
COPY requirements.txt /tmp/requirements.txt
RUN set -ex && \
pip install --upgrade pip && \
pip install -r /tmp/requirements.txt && \
pip install --no-cache-dir psycopg2-binary==2.9.1 && \
rm -rf /root/.cache/
COPY . /code
RUN python manage.py collectstatic --noinput
CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "backend.wsgi"]
# fly.toml app configuration file generated for cinema-memory on 2023-05-30T23:39:12-03:00
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
app = "cinema-memory"
primary_region = "eze"
console_command = "/code/manage.py shell"
release_command = "python manage.py migrate"
PORT = "8000"
internal_port = 8000
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
guest_path = "/code/static"
url_prefix = "/static/"
Hi @yasserpulido !
I need some additional info about the issue you are facing.
Where are you serving your static files from?
When you say “save an image” here, do you mean, add a new image to your static folder and redeploy your app?
Can you find your static files when you deploy and then they disappear from your static folder?
Could you explain a bit more about it, please?
Well, I figure it out that the filesystem gets reset everytime the machine restarts. So, I created a volumes associate to the django project, and save images in that folder.
But, for example I save 5 images, 4 of them are visible by
fly ssh console but the rest one is not visible by ssh but it visible by url. Is this happening because I create two volumes? and how I can see that one.
All your static files would still be in your image when the machine restarts, unless you are uploading new images. If so, we are probably talking about files uploaded by a user and dynamically created by the application. Is that the case?
Yes that is the case, files uploaded by a user. I created volumes relate to that project, in a folder outside the django project, so when the machine restarts the media folder is not affected. In the django settings project I set that path.
@yasserpulido That’s right!
In the static folder you can have files such as images, js and CSS files for you application.
As you already figure it our, what you are referring to are “media files”. Here you can find more information about it: Managing files | Django documentation | Django.