Dockerfile 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. FROM golang:1.19 as builder
  2. RUN echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib\n\
  3. deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib\n\
  4. deb http://mirrors.163.com/debian/ jessie-backports main non-free contrib\n\
  5. deb-src http://mirrors.163.com/debian/ jessie main non-free contrib\n\
  6. deb-src http://mirrors.163.com/debian/ jessie-updates main non-free contrib\n\
  7. deb-src http://mirrors.163.com/debian/ jessie-backports main non-free contrib\n\
  8. deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib\n\
  9. deb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib\n\
  10. deb http://ftp.cn.debian.org/debian jessie main" > /etc/apt/sources.list
  11. # install gcc
  12. RUN apt-get update && apt-get install -y --no-install-recommends \
  13. g++ \
  14. gcc \
  15. libc6-dev \
  16. make \
  17. pkg-config \
  18. && apt-get install -y curl git unzip vim iputils-ping wget \
  19. && rm -rf /var/lib/apt/lists/*
  20. WORKDIR /workspaces
  21. COPY . ./
  22. ENV GOPROXY=https://goproxy.cn,direct
  23. RUN go get -d -v ./
  24. RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo -o demo -ldflags="-w -s" main.go
  25. FROM alpine:latest as runner
  26. WORKDIR /app
  27. COPY --from=builder /app/main .
  28. COPY --from=builder /app/config ./config
  29. RUN echo "https://mirrors.aliyun.com/alpine/v3.8/main/" > /etc/apk/repositories \
  30. && echo "https://mirrors.aliyun.com/alpine/v3.8/community/" >> /etc/apk/repositories \
  31. && apk add --no-cache tzdata \
  32. && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
  33. && echo Asia/Shanghai > /etc/timezone \
  34. && apk del tzdata
  35. EXPOSE 8888
  36. VOLUME ["/app/config","/app/log", "/workspaces"]
  37. ENTRYPOINT ["./main"]
  38. # CMD [ "/app/demo" ]
  39. CMD [ "/bin/bash" ]