Skip to content

Instantly share code, notes, and snippets.

@zsmatrix62
Last active April 21, 2020 17:47
Show Gist options
  • Save zsmatrix62/6120a538e1cadf10f7ae9ee3e9801479 to your computer and use it in GitHub Desktop.
Save zsmatrix62/6120a538e1cadf10f7ae9ee3e9801479 to your computer and use it in GitHub Desktop.
# 修改内置 Debian 源 - 阿里云国内加速
RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
# 解决镜像太大的问题 & 修正时区
FROM alpine:latest
# 安装 /bin/bash 方便调试
RUN echo "https://mirror.tuna.tsinghua.edu.cn/alpine/v3.4/main/" > /etc/apk/repositories
RUN apk update \
&& apk upgrade \
&& apk add --no-cache bash \
bash-doc \
bash-completion \
&& rm -rf /var/cache/apk/* \
&& /bin/bash
# 安装证书 解决http请求
RUN apk add --update ca-certificates
RUN update-ca-certificates
# 统一亚洲时区
RUN apk add --no-cache tzdata
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezon
# CentOS 8.1
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
# 浏览 https://download.docker.com/linux/centos 选择最新安装包
dnf install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
sudo yum install -y docker-ce docker-ce-cli
sudo systemctl start docker
sudo systemctl enable docker
FROM golang:1.14.2-stretch as builder
# 配置代理
ENV GOPROXY https://goproxy.cn
# 设置go缓存
ENV GO111MODULE=on
# go缓存
WORKDIR /go/cache
ADD go.mod .
ADD go.sum .
RUN go mod download
# 项目工作路径
WORKDIR /go/release
# 增加所有的项目到该工作路径下
ADD . .
# 运行命令
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app main.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment