mirror of
https://github.com/LiuYuYang01/ThriveX-Blog.git
synced 2026-09-03 06:24:24 +08:00
1. 重写Dockerfile,采用多阶段构建并使用国内镜像源,提升构建速度 2. 简化API地址获取逻辑,移除内部环境变量判断 3. 新增配置请求校验函数,统一处理接口异常情况 4. 更新.dockerignore,忽略更多无关文件并保留必要配置 5. 新增Docker运行教程文档
2.0 KiB
2.0 KiB
Docker 运行教程
环境变量
.env 里有两个变量
NEXT_PUBLIC_PROJECT_API
后端 API 接口地址
NEXT_PUBLIC_PROJECT_API=https://你的域名/api
注意: 注意生产环境一定要是 https 域名
CACHE_CLIENT_STALE
缓存时间,以秒为单位
CACHE_CLIENT_STALE=300
表示 300 秒内优先使用缓存,不会频繁请求服务端,推荐配置,可以非常有效减轻服务器压力。
如果你不想开启缓存,就把值改成 CACHE_CLIENT_STALE=1
注意: 配置缓存后,在缓存时间内修改控制端信息会导致 无法实时生效
构建镜像
在项目根目录执行:
docker build --build-arg NEXT_PUBLIC_PROJECT_API=https://你的域名/api -t thrivex-blog .
如果是本地测试,可以写:
docker build --build-arg NEXT_PUBLIC_PROJECT_API=https://localhost:9003/api -t thrivex-blog .
NEXT_PUBLIC_PROJECT_API 是构建时变量,必须在 docker build 时传进去
启动容器
docker run -d --name thrivex-blog -p9001:9001 --env-file .env thrivex-blog
配置说明:
-d:后台运行--name thrivex-blog:容器名称-p9001:9001:把容器9001端口映射到本机9001--env-file .env:把.env里的运行时变量传给容器thrivex-blog:镜像名称
访问页面
本地访问:
http://localhost:9001
服务器直接访问:
http://服务器IP:9001
域名访问:
https://你的域名
其他
查看容器
docker ps --filter "name=thrivex-blog"
查看日志
docker logs -f thrivex-blog
停止容器
docker stop thrivex-blog
删除容器
docker rm -f thrivex-blog
重新构建并启动
docker rm -f thrivex-blog
docker build --build-arg NEXT_PUBLIC_PROJECT_API=https://你的域名/api -t thrivex-blog .
docker run -d --name thrivex-blog -p9001:9001 --env-file .env thrivex-blog