-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockerfile-golang
54 lines (43 loc) · 1.76 KB
/
dockerfile-golang
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 基础镜像
FROM centos:8
# 编写者
LABEL maintainer="[email protected]"
# golang版本
ARG golang_version
# 安装目录
ARG install_path
# gopath目录
ARG gopath
# 系统包 如vim、lrzsz等
ARG extra_packages=vim
# 系统代理
ARG proxy=socks5://docker.for.mac.host.internal:1087
ENV LANG C.UTF-8
RUN yum install -y wget $extra_packages \
# 时区设置
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" >> /etc/timezone \
# 切换镜像源
&& wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo \
&& yum clean all && yum makecache \
# 安装基于系统的一些依赖
&& yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel libxslt-devel gd gd-devel \
pcre pcre-devel epel-release \
# 系统别名设置
&& echo -e "alias wget=\"wget -U\" \nalias ll=\"ls -l\" \n" >> /etc/bashrc \
# 系统代理设置
&& echo -e "alias setProxy=\"export ALL_PROXY=$proxy; echo -e '已开启代理'\" \nalias unsetProxy=\"unset ALL_PROXY; echo -e '已关闭代理'\" \nalias ip=\"curl cip.cc\" \n" >> /etc/bashrc \
# 下载安装包
&& cd /tmp && wget -c https://golang.google.cn/dl/go$golang_version.linux-amd64.tar.gz \
# 解压源码包到制定安装位置
&& tar zxvf go$golang_version.linux-amd64.tar.gz && mv go $install_path \
# 环境变量设置
&& echo "export GOPATH=$gopath" >> /etc/bashrc \
&& echo "export GOROOT=$install_path" >> /etc/bashrc \
&& echo 'export PATH=$PATH:$GOROOT/bin' >> /etc/bashrc \
&& source /etc/bashrc \
# 代理
&& go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct \
# 删除无用的文件,使镜像文件足够小
&& yum clean all && rm -rf /tmp/*
WORKDIR /