Merge pull request #18 from Latezly/main

添加Docker运行方式 #10
This commit is contained in:
hzm0321
2026-02-06 08:29:04 +08:00
committed by GitHub
4 changed files with 99 additions and 0 deletions

56
.github/workflows/docker-ci.yml vendored Normal file
View File

@@ -0,0 +1,56 @@
name: Docker CI
on:
push:
branches:
- main
pull_request:
jobs:
dockerfile-check:
name: Build & Test Dockerfile
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build Dockerfile image
run: docker build -t real-time-fund .
- name: Run Dockerfile container
run: |
docker run -d --name fund -p 3000:3000 real-time-fund
echo "Waiting 10 seconds for the container to start..."
sleep 10
- name: Test service
run: |
curl -f http://localhost:3000 || (docker logs fund && exit 1)
- name: Cleanup
run: |
docker stop fund
docker rm fund
docker-compose-check:
name: Build & Test Docker Compose
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Docker Compose up
run: |
docker compose up -d --build
echo "Waiting 10 seconds for services to start..."
sleep 10
- name: Test app service
run: |
curl -f http://localhost:3000 || (docker compose logs app && exit 1)
- name: Cleanup
run: docker compose down

19
Dockerfile Normal file
View File

@@ -0,0 +1,19 @@
# ===== 构建阶段 =====
FROM node:18-bullseye AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install --legacy-peer-deps
COPY . .
RUN npx next build
# ===== 运行阶段 =====
FROM node:18-bullseye AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/package.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD wget -qO- http://localhost:3000 || exit 1
CMD ["npm", "start"]

View File

@@ -54,6 +54,23 @@ npm run build
```
静态文件将生成在 `out` 目录下。
### Docker运行
1. 构建镜像
```
docker build -t real-time-fund .
```
2. 启动容器
```
docker run -d -p 3000:3000 --name fund real-time-fund
```
#### docker-compose
```
docker compose up -d
```
## 📖 使用说明
1. **添加基金**:在顶部输入框输入 6 位基金代码(如 `110022`),点击“添加”。

7
docker-compose.yml Normal file
View File

@@ -0,0 +1,7 @@
services:
app:
build: .
ports:
- "3000:3000"
restart: always