From dca76969ebcb8a1ccb97c4c2950aba2b3a10f164 Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Thu, 10 Aug 2023 14:19:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=A8=8B=E5=BA=8F=E6=BA=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9B=B4=E6=96=B0=E4=BA=86=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E6=98=AF=20docker=20container=20=E4=B8=AD=E7=9A=84=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E6=BA=90=E6=96=87=E4=BB=B6=E6=B2=A1=E6=9C=89=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题出在 build.sh 中的 --mount type=volume,src=englishpal-db,target=/app 。 运行 docker container 时,会将整个 englishpal-db 对应的文件夹 /var/lib/docker/volumes/englishpal-db/_data 下面的内容拷贝到 docker container 里面的 /app 文件夹下面。 然而,/var/lib/docker/volumes/englishpal-db/_data 下面的源程序文件并不是最新的(比如其 main.py 是 7月17日的)。 将 target=/app 改为 target=/app/db。即可解决问题。 --- Dockerfile | 6 +++--- app/Article.py | 2 +- app/model/__init__.py | 2 +- app/templates/login.html | 1 - app/templates/mainpage_get.html | 1 + build.sh | 5 +---- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9ff75dc..55e5946 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM tiangolo/uwsgi-nginx-flask:python3.8-alpine -COPY requirements.txt /app -RUN pip3 install -U pip -RUN pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ +COPY requirements.txt /tmp COPY ./app/ /app/ +RUN pip3 install -U pip -i https://mirrors.aliyun.com/pypi/simple/ +RUN pip3 install -r /tmp/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ diff --git a/app/Article.py b/app/Article.py index 4b7632f..b24e448 100644 --- a/app/Article.py +++ b/app/Article.py @@ -11,7 +11,7 @@ from difficulty import get_difficulty_level_for_user, text_difficulty_level, use path_prefix = '/var/www/wordfreq/wordfreq/' -path_prefix = './' # comment this line in deployment +path_prefix = './db/' # comment this line in deployment def total_number_of_essays(): diff --git a/app/model/__init__.py b/app/model/__init__.py index a360d0c..f5256a2 100644 --- a/app/model/__init__.py +++ b/app/model/__init__.py @@ -1,7 +1,7 @@ from pony.orm import * db = Database() -db.bind("sqlite", "../wordfreqapp.db", create_db=True) # bind sqlite file +db.bind("sqlite", "../db/wordfreqapp.db", create_db=True) # bind sqlite file class User(db.Entity): diff --git a/app/templates/login.html b/app/templates/login.html index 81f7e0e..794be80 100644 --- a/app/templates/login.html +++ b/app/templates/login.html @@ -39,7 +39,6 @@ 注册 - {% endif %} diff --git a/app/templates/mainpage_get.html b/app/templates/mainpage_get.html index 344943d..e96e8dc 100644 --- a/app/templates/mainpage_get.html +++ b/app/templates/mainpage_get.html @@ -44,6 +44,7 @@ {{x[0]}} {{x[1]}} {% endfor %} {% endif %} +

Version: 20230810

{{ yml['footer'] | safe }} diff --git a/build.sh b/build.sh index c86c07b..158a86f 100755 --- a/build.sh +++ b/build.sh @@ -3,9 +3,6 @@ DEPLOYMENT_DIR=/home/lanhui/englishpal2/EnglishPal cd $DEPLOYMENT_DIR pwd -# Install dependencies - -#pip3 install -r requirements.txt # Stop service sudo docker stop EnglishPal @@ -15,7 +12,7 @@ sudo docker rm EnglishPal sudo docker build -t englishpal . # Run the application -sudo docker run --restart=always -d --name EnglishPal -p 90:80 -v ${DEPLOYMENT_DIR}/app/static/frequency:/app/static/frequency --mount type=volume,src=englishpal-db,target=/app -t englishpal # for permanently saving data +sudo docker run --restart=always -d --name EnglishPal -p 90:80 -v ${DEPLOYMENT_DIR}/app/static/frequency:/app/static/frequency --mount type=volume,src=englishpal-db,target=/app/db -t englishpal # for permanently saving data # Save space. Run it after sudo docker run sudo docker system prune -a -f