Skip to content

Commit 133059c

Browse files
committed
update: docker build
1 parent d8fc5ae commit 133059c

3 files changed

Lines changed: 21 additions & 54 deletions

File tree

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,22 @@ mkBlog 是一个轻量级的个人博客系统,支持 Markdown 文章、文章
8080

8181
**数据库 Docker 部署:**
8282

83+
自行解决 MySQL 和 Postgres 的需求。默认采用的 SQLite3 不需要额外部署数据库。
84+
8385
```bash
84-
cd docker
85-
docker-compose up -d
86+
# 自动拉取,注意配置网络
87+
docker pull mkitsdts/mkblog:latest
88+
docker run -d --name mkblog -p 4801:4801 -v /etc/mkblog:/app/data mkitsdts/mkblog:latest
8689
```
8790

91+
```bash
92+
# 手动构建(比较耗时,建议优先用上面)
93+
docker build -f docker/Dockerfile -t mkblog:latest .
94+
docker run -d --name mkblog -p 4801:4801 -v /etc/mkblog:/app/data mkblog:latest
95+
```
96+
97+
通过docker部署后,配置文件会被写入到 /etc/mkblog目录下。
98+
8899
## 访问地址
89100

90101
前后端统一地址,所以没有跨域问题

docker/Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#
2-
FROM golang:tip-alpine AS backend
1+
#
2+
FROM golang:1.24-alpine AS backend
33
WORKDIR /app
44

55
RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.tuna.tsinghua.edu.cn/alpine#g' /etc/apk/repositories
@@ -10,7 +10,11 @@ COPY . .
1010
RUN go env -w GOPROXY=https://goproxy.io,direct
1111
RUN go mod tidy
1212

13-
RUN CGO_ENABLED=1 GOOS=linux go build -o /app/main .
13+
RUN CGO_ENABLED=1 \
14+
GOOS=linux \
15+
GOGC=20 \
16+
GOMAXPROCS=2 \
17+
go build -ldflags="-s -w" -o /app/main .
1418

1519
#
1620
FROM alpine:3.22
@@ -19,9 +23,7 @@ WORKDIR /app
1923
COPY --from=backend /app/main .
2024

2125
COPY --from=backend /app/static ./static
22-
# 复制配置文件
23-
COPY config.yaml ./config.yaml
2426

25-
EXPOSE 8080 6060
27+
EXPOSE 4801 6060
2628

2729
CMD ["./main"]

docker/docker-compose.yaml

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)