go1.19.3下载 Downloads - The Go Programming Language (google.cn)
Dockerfile文件
1.kvrocks_controller编译
FROM centos as builder # centos 默认当前是centos8
# go 环境安装
COPY go1.19.3.linux-amd64.tar.gz /opt/
RUN cd /opt \
&& tar -C /usr/local -xzf go1.19.3.linux-amd64.tar.gz \
&& rm -rf go1.19.3.linux-amd64.tar.gz
ENV PATH $PATH:/usr/local/go/bin
RUN mkdir -p /home/work/go \
&& export GOPATH=/home/work/go \
&& go env -w GO111MODULE=on \
&& go env -w GOPROXY=https://goproxy.cn \
&& go env -w CGO_ENABLED=0\
&& mkdir -p $GOPATH/src
# 解决centos8 yum install 问题
RUN cd /etc/yum.repos.d/ \
&& mkdir backup && mv *repo backup/ \
&& curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo \
&& sed -i -e "s|mirrors.cloud.aliyuncs.com|mirrors.aliyun.com|g " /etc/yum.repos.d/CentOS-* \
&& sed -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-* \
&& echo "export LC_ALL=en_US.utf8" >> /etc/profile
RUN yum install -y make git
RUN cd /home/work/go/src/ && git clone https://github.com/KvrocksLabs/kvrocks_controller && cd kvrocks_controller && make
2.tendisplus_exporter编译
FROM centos as builder
COPY go1.15.2.linux-amd64.tar.gz /opt/
RUN cd /opt \
&& tar -C /usr/local -xzf go1.15.2.linux-amd64.tar.gz \
&& rm -rf go1.15.2.linux-amd64.tar.gz
ENV PATH $PATH:/usr/local/go/bin
RUN mkdir -p /home/work/go \
&& export GOPATH=/home/work/go \
&& go env -w GO111MODULE=on \
&& go env -w GOPROXY=https://goproxy.cn \
&& go env -w CGO_ENABLED=0\
&& mkdir -p $GOPATH/src
RUN cd /home/work/go/src/ && git clone https://github.com/zhaochunxue/tendisplus_exporter.git && go build -o tendisplus_exporter
# ENTRYPOINT ["/home/work/go/src/tendisplus_exporter/tendisplus_exporter"]
FROM alpine
COPY --from=builder /home/work/go/src/tendisplus_exporter/tendisplus_exporter /usr/local/bin/
RUN chmod 777 /usr/local/bin/tendisplus_exporter
ENTRYPOINT ["/usr/local/bin/tendisplus_exporter"]
咱也不是go语言学习者就是有时候会需要编译go的东西,省的来回的搭建go环境就很烦,这样会轻便许多,编译之后的文件可以直接拿出来到别的地方使用或者是在这个镜像基础上像第二个案例一样使用