nextconnect / Dockerfile
ZHZ1024's picture
Upload 14 files
34fee23 verified
raw
history blame contribute delete
896 Bytes
# 使用多阶段构建
FROM golang:1.18-alpine AS builder
# 设置工作目录
WORKDIR /app
# 复制go.mod和go.sum文件
COPY go.mod go.sum ./
# 下载依赖
RUN go mod download
# 复制源代码
COPY . .
# 编译应用程序
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o nextconnect .
# 使用轻量级基础镜像
FROM alpine:latest
# 安装必要的包
RUN apk --no-cache add ca-certificates
# 创建非root用户
RUN addgroup -g 1000 nextconnect && adduser -D -s /bin/sh -u 1000 -G nextconnect nextconnect
# 设置工作目录
WORKDIR /root/
# 从builder阶段复制二进制文件
COPY --from=builder /app/nextconnect .
# 复制配置文件
COPY --from=builder /app/config.ini .
# 更改文件权限
RUN chown nextconnect:nextconnect nextconnect
# 切换到非root用户
USER nextconnect
# 暴露端口
EXPOSE 7000
# 设置默认命令
CMD ["./nextconnect"]