整体思路:
在原有的rancher/rancher:v2.5.8,叠加go,gdb等工具,作为一个可以分发的开发镜像
rancher编译环境搭建:
0.下载rancher镜像并运行起来
拉取rancher镜像:
docker image pull rancher/rancher:v2.5.8
启动rancher容器:
docker run -d --privileged --restart=unless-stopped -p 80:80 -p 443:443 --name rancher rancher/rancher:v2.5.8
1.编译过程(在rancher的容器中执行):
yum -y install gcc.x86_64 gcc-c++
yum install glibc-static.x86_64 -y
yum -y install git
git clone https://github.com.cnpmjs.org/rancher/rancher/
yum install epel-release
golang二进制安装,默认的是1.15版本,编译rancher需要1.16以上,因为1.16以下没有embed会导致报错
wget https://dl.google.com/go/go1.17.2.linux-amd64.tar.gz
tar -C /usr/local/ -xzvf ./go1.17.2.linux-amd64.tar.gz
vi /root/.bash_profile
export PATH=$PATH:/usr/local/go/bin
source /root/.bash_profile
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
//去掉编译优化
go env -w CGO_CFLAGS="-g "
go env -w CGO_CXXFLAGS="-g "
go env -w CGO_FFLAGS="-g "
go env -w CGO_LDFLAGS="-g "
修改编译选项,将-s去掉,保留调试符号:
vi ./scripts/build-server
2.构建可用镜像
构建完成后commit容器,保存为镜像
docker commit 8b9c8556c83a rancher/rancher_develop_v1:v2.5.8
保存镜像到本地
docker save rancher/rancher_develop_v1 > ./rancher_develop_v1.tar
docker load -i ./rancher_develop_v1.tar
3.启动
需要将宿主机上的代码挂载到容器的/var/lib/rancher/build目前
docker run -d --privileged --restart=unless-stopped --name=rancher_develop_v1 -p 80:80 -p 443:443 -p 2379:2379 -v /home/lyj/rancher/rancher:/var/lib/rancher/build rancher/rancher_develop_v1:v2.5.8
./rancher --http-listen-port=80 --https-listen-port=443 --audit-log-path=/rancher-api-audit.log --audit-level=0 --audit-log-maxage=10 --audit-log-maxbackup=10 --audit-log-maxsize=100