38 lines
1.4 KiB
Docker
38 lines
1.4 KiB
Docker
# golang环境编译 docker build -t dev.daymele.com:5000/res .
|
||
FROM golang:latest as build
|
||
ENV GO111MODULE on
|
||
ENV GOPROXY=https://goproxy.io
|
||
WORKDIR /
|
||
# 通过提前运行go mod download可以使用cache编译,避免每次编译都下载,加快编译速度
|
||
COPY go.mod go.sum ./
|
||
RUN go mod download
|
||
ADD . /
|
||
RUN GOOS=linux CGO_ENABLED=0 go build -o adapt -ldflags="-w -s"
|
||
|
||
# 生成alpine部署容器
|
||
FROM alpine:latest
|
||
LABEL MAINTAINER='LIU Peng<liupeng@daymele.com>'
|
||
WORKDIR /
|
||
COPY --from=build /adapt /adapt
|
||
|
||
# 健康检测
|
||
ADD ./hc.sh /root/healthcheck.sh
|
||
HEALTHCHECK --start-period=60s --interval=15s --timeout=5s --retries=3 CMD /bin/ash /root/healthcheck.sh
|
||
|
||
# 时区处理(方法一:需要提前准备下两条,scratch和alpine都可以使用)
|
||
# tar cfz zoneinfo.tar.gz /usr/share/zoneinfo
|
||
# cp /usr/share/zoneinfo/PRC PRC
|
||
ADD PRC /etc/localtime
|
||
ADD zoneinfo.tar.gz /
|
||
# 设置时区为上海
|
||
#RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
|
||
#RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
||
# && echo "Asia/Shanghai" > /etc/timezone \
|
||
# && apk del tzdata \
|
||
# && rm -rf /var/cache/apk/*
|
||
ENTRYPOINT ["/adapt","-port","9000","-conf","/conf/daymele.conf"]
|
||
EXPOSE 9000
|
||
|
||
# docker image prune 删除悬虚镜像
|
||
# docker run --name res -d -p 7000:7011 -v /mnt/resdata:/data dev.daymele.com:5000/res --restart always
|