增加加速镜像

This commit is contained in:
yml2213
2026-07-15 16:09:05 +08:00
parent 0d3543fd4b
commit 3dbd81cf49
3 changed files with 65 additions and 6 deletions
+22 -2
View File
@@ -38,14 +38,34 @@ sudo usermod -aG docker "$USER"
docker compose version
```
4. 上传代码到服务器,例如:
4. **(强烈建议)Docker 镜像加速** —— 加速拉 `golang` / `node` / `nginx` / `postgres` 等基础镜像。
腾讯云 CVM 可写(其它云可换成对应镜像地址):
```bash
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<'EOF'
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com"
]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
docker info | grep -A5 'Registry Mirrors'
```
说明:Dockerfile 内已默认使用 **腾讯云 Alpine 源、goproxy.cn、npmmirror**,加速构建阶段的 `apk` / `go mod` / `npm ci`
基础镜像本身仍依赖上面的 Docker Hub 镜像加速。
5. 上传代码到服务器,例如:
```bash
git clone <你的仓库地址> kefu_cloud
cd kefu_cloud
```
5. 部署前检查端口占用:
6. 部署前检查端口占用:
```bash
sudo ss -tlnp | grep -E ':80|:443|:18080'
+22 -2
View File
@@ -1,14 +1,28 @@
# 客服云 API — 生产镜像(多阶段构建)
# build context: 仓库根目录
# docker build -f deploy/docker/Dockerfile.api -t kefu-api:latest .
#
# 国内加速(默认开启):Alpine 清华源 + goproxy.cn
# 海外构建可覆盖:
# docker build --build-arg ALPINE_MIRROR=dl-cdn.alpinelinux.org \
# --build-arg GOPROXY=https://proxy.golang.org,direct ...
FROM golang:1.24-alpine AS builder
ARG ALPINE_MIRROR=mirrors.cloud.tencent.com
ARG GOPROXY=https://goproxy.cn,direct
# 若 go.mod 要求更高版本,自动下载 toolchain
ENV GOTOOLCHAIN=auto
ENV CGO_ENABLED=0
ENV GOPROXY=${GOPROXY}
ENV GOSUMDB=sum.golang.google.cn
RUN apk add --no-cache git ca-certificates tzdata
RUN set -eux; \
if [ -n "${ALPINE_MIRROR}" ]; then \
sed -i "s#dl-cdn.alpinelinux.org#${ALPINE_MIRROR}#g" /etc/apk/repositories; \
fi; \
apk add --no-cache git ca-certificates tzdata
WORKDIR /src
@@ -26,7 +40,13 @@ RUN GOOS=linux GOARCH=amd64 \
FROM alpine:3.21
RUN apk add --no-cache ca-certificates tzdata wget \
ARG ALPINE_MIRROR=mirrors.cloud.tencent.com
RUN set -eux; \
if [ -n "${ALPINE_MIRROR}" ]; then \
sed -i "s#dl-cdn.alpinelinux.org#${ALPINE_MIRROR}#g" /etc/apk/repositories; \
fi; \
apk add --no-cache ca-certificates tzdata wget \
&& adduser -D -H -u 10001 kefu
ENV TZ=Asia/Shanghai
+21 -2
View File
@@ -1,18 +1,37 @@
# 客服云前端 — Nginx 托管静态资源并反代 API / 文件
# build context: 仓库根目录
#
# 国内加速(默认开启):Alpine 腾讯云源 + npmmirror
# 海外构建可覆盖:
# docker build --build-arg ALPINE_MIRROR=dl-cdn.alpinelinux.org \
# --build-arg NPM_REGISTRY=https://registry.npmjs.org ...
FROM node:22-alpine AS builder
ARG ALPINE_MIRROR=mirrors.cloud.tencent.com
ARG NPM_REGISTRY=https://registry.npmmirror.com
RUN set -eux; \
if [ -n "${ALPINE_MIRROR}" ]; then \
sed -i "s#dl-cdn.alpinelinux.org#${ALPINE_MIRROR}#g" /etc/apk/repositories; \
fi
WORKDIR /web
COPY web/package.json web/package-lock.json ./
RUN npm ci
RUN npm ci --registry="${NPM_REGISTRY}"
COPY web/ ./
RUN npm run build
FROM nginx:1.27-alpine
RUN apk add --no-cache tzdata \
ARG ALPINE_MIRROR=mirrors.cloud.tencent.com
RUN set -eux; \
if [ -n "${ALPINE_MIRROR}" ]; then \
sed -i "s#dl-cdn.alpinelinux.org#${ALPINE_MIRROR}#g" /etc/apk/repositories; \
fi; \
apk add --no-cache tzdata \
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo Asia/Shanghai > /etc/timezone