docker方式部署qexo😘
参考:
https://github.com/Qexo/Qexo.git (源码文件)
https://www.yyds.space/posts/3dfeb390abb4
概览:
1. 创建配置文件目录及空数据库文件
1 2 3 4 5 6 7 8 9 10 11
| mkdir -p /app/db /app/data touch /app/db/db.sqlite3
mkdir -p /data/qexo mkdir -p /data/qexo/db cd /data/qexo/db && touch db.sqlite3
cd /data/qexo && rz
vim Dockerfile
|
2. Dockerfile文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| FROM python:3.11.3-alpine
LABEL maintainer="xwgegewu@gmail.com"
RUN pip config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple/
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \ apk --no-cache add tzdata && \ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ apk --no-cache del tzdata && \ apk --no-cache add git && \ mkdir /app
WORKDIR /app
ADD ./Qexo.tar.gz /app/ RUN mv /app/Qexo/* /app/
RUN pip install --upgrade pip RUN apk --no-cache add build-base python3-dev libffi-dev RUN pip install Django==3.2.18 RUN pip install PyMySQL==1.0.2 RUN pip install boto3==1.26.94 RUN pip install requests==2.28.2 RUN pip install PyGithub==1.58.1 RUN pip install python-gitlab==3.13.0 RUN pip install html2text==2020.1.16 RUN pip install PyYAML RUN pip install urllib3==1.26.15 RUN pip install Markdown==3.4.1 RUN pip install djongo==1.3.6 RUN pip install django-cors-headers==3.14.0 RUN pip install pymongo==3.13.0 RUN pip install dnspython==2.2.1 RUN pip install sqlparse==0.2.4 RUN pip install psycopg2-binary==2.9.5 RUN pip install cryptography==39.0.2 RUN pip install pyopenssl==23.0.0 RUN pip install oss2==2.17.0 RUN pip install beautifulsoup4==4.11.2
COPY . /app/ RUN chmod +x /app/run.sh
EXPOSE 8000
VOLUME ["/app/db", "/app/data"]
ENTRYPOINT ["/bin/sh", "/app/run.sh"]
|
3. 在/data/qexo创建配置文件
configs.py
DOMAINS处需要加上自己的本机IP或者域名 相当于设置白名单
1 2 3 4 5 6 7 8 9 10 11 12
| cd /data/qexo && vim configs.py
import pymysql,os
DOMAINS = ["127.0.0.1","10.0.0.10"] DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join('/app/db' , 'db.sqlite3'), } }
|
run.sh
1 2 3 4 5
| #!/bin/bash
python3 manage.py makemigrations python3 manage.py migrate python3 manage.py runserver 0.0.0.0:8000 --noreload
|
构建docker镜像 启动容器
1 2 3 4
| docker build -t qexo:3.0.2 .
docker run -d --name qexo -p 8000:8000 -v /data/qexo/db:/app/db -v /data/blog:/app/data qexo:3.0.2
|
查看docker日志是否成功运行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| docker logs qexo
获取本地配置文件成功, 使用本地数据库配置 _ _ /\ | | | | / \ | |__ _ _ __| |_ _ / /\ \ | |_ \| | | |/ _| | | | | / ____ \| |_) | |_| | (_| | |_| | /_/ \_\____/ \____|\____|\____| 当前环境: 本地 Operations to perform: Apply all migrations: auth, contenttypes, hexoweb, sessions Running migrations: No migrations to apply. [25/Jan/2024 07:11:16] ERROR: Provider获取失败, 跳过(functions.py.<module>[line:55]) [25/Jan/2024 07:11:40] "GET / HTTP/1.1" 302 0 [25/Jan/2024 07:11:40] INFO: 未检测到初始化配置, 转跳到初始化页面(views.py.login_view[line:40]) [25/Jan/2024 07:11:40] "GET /login/?next=/ HTTP/1.1" 302 0 [25/Jan/2024 07:11:40] INFO: 保存设置CDN_PREV => https://unpkg.com/(functions.py.save_setting[line:259]) [25/Jan/2024 07:11:40] INFO: 保存设置QEXO_NAME => Hexo管理面板(functions.py.save_setting[line:259])
|
浏览器访问: http://本机IP:8000 完成各项初始化等配置。
4. 最后推送到阿里云镜像栈(略)并使用阿里云镜像构建容器
1 2 3
| docker login .... docker tag ..... docker push .....
|