34 lines
853 B
Docker
34 lines
853 B
Docker
FROM golang:alpine as builder
|
|
# 设置工作目录
|
|
WORKDIR /devttl
|
|
# 将当前目录内容拷到工作目录 (相对路径)
|
|
COPY . .
|
|
|
|
# 配置 golang 环境
|
|
RUN go env -w GO111MODULE=on \
|
|
&& go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct \
|
|
&& go mod tidy \
|
|
&& go build -o main .
|
|
|
|
# 使用更小的基础镜像
|
|
FROM alpine:latest
|
|
|
|
# 设置工作目录
|
|
WORKDIR /devttl
|
|
ENV WORK_PATH /devttl
|
|
|
|
WORKDIR ${WORK_PATH}
|
|
|
|
# 从构建阶段复制二进制文件
|
|
COPY --from=builder ${WORK_PATH}/main .
|
|
COPY --from=0 ${WORK_PATH}/config/config.yaml ./config/
|
|
COPY --from=0 ${WORK_PATH}/config/google.xdb ./config/
|
|
|
|
# 暴露端口
|
|
EXPOSE 80
|
|
|
|
# 如果不使用上面的方式需要打开下面这行注释
|
|
# ENTRYPOINT ./main -c config.docker.toml
|
|
|
|
###############################################
|
|
CMD ["./main","-c","./config/config.yaml"] |