I'm using docker and docker-compose to deploy my flask app (btw I noticed the same issue with my django app as well). The issue is: when I start adding some static files or sqlite data to database.db it works fine while I'm running in docker, but when I restart my containers all data and static files are just gone. It seems like docker doesn't store data and just keep it inside the container. I added volumes to my service and it still doesn't work unfortunately.
My docker-compose.yml
:
1 version: '3.5'
1
2 services:
3 flask_app:
4 container_name: flask_app
5 build:
6 context: .
7 dockerfile: Dockerfile
8 environment:
9 - TBOT_SECRET_KEY='youwillneverguess'
10 - TBOT_ADMIN_PASSWORD='qwerty'
11 - TBOT_ADMIN_USERNAME='admin'
12 ports:
13 - "80:5000"
14 restart: always
15 volumes:
! 16 - db:/var/lib/tarkov_bot/data
17
18 volumes:
! 19 db:
and the Dockerfile
:
2 FROM python:3.7
1
2 # create and set working directory
3 RUN mkdir /app
4 WORKDIR /app
5
6 # Add current directory code to working directory
7 ADD . /app/
8
9 # set default environment variables
10 ENV PYTHONUNBUFFERED 1
11 ENV LANG C.UTF-8
12 ENV DEBIAN_FRONTEND=noninteractive
13
14 # Install system dependencies
15 RUN apt-get update && apt-get install -y --no-install-recommends \
16 tzdata \
17 python3-setuptools \
18 python3-pip \
19 python3-dev \
20 python3-venv \
21 git \
22 && \
23 apt-get clean && \
24 rm -rf /var/lib/apt/lists/*
25
26
27 # install environment dependencies
28 RUN pip3 install --upgrade pip
29
30 # Install project dependencies
31 RUN pip3 install -r requirements.txt
32
33 EXPOSE 5000
34
35 CMD gunicorn -b 0.0.0.0:5000 app:app
~
I'm affraid docker volumes
is the way to do that. If it's not working, it means that you need to mount more volumes where desired-persistent data are being stored.
Another possibility, not so elegant, is doing docker commit
to save snapshot of your current docker, and save it as a new image.
I recommend first purpose: investigate what other files you need to save in your mounted volumes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.