http://ask.loongnix.org/?/article/90
一、下载portainer官方镜像
1.在loongnix上下载镜像
[root@loongson ~]# docker pull docker.io/portainer/portainer:1.14.3 Using default tag: 1.14.3 Trying to pull repository docker.io/portainer/portainer ... unauthorized: authentication required
2.根据控制台反馈结果unauthorized: authentication required,提示无权限,因为该镜像不支持 mips64el,所以无法下载镜像到本地,可使用X86机器进行下载该镜像
[root@X86 ~]# docker pull docker.io/portainer/portainer:1.14.3
3.提示下载成功,查看本地镜像
[root@X86 ~]# docker images REPOSITORY TAG IMAGE ID docker.io/portainer/portainer 1.14.3 457fb8fa57b0
4.确认本地镜像docker.io/portainer/portainer已存在,运行该镜像
[root@X86 ~]# docker run -i -t docker.io/portainer/portainer:1.14.3
5.使用Docker export命令导出当前镜像创建的容器为tar包
[root@X86 ~]# docker export 36ceef361070 > loongson-portainer.tar
6.将loongson-portainer.tar包拷贝到loongson机器上,这里使用scp命令进行拷贝
[root@X86 ~]# scp loongson-portainer.tar [email protected]:/root/portainer/
7.在loongnix机器上解压loongson-portainer.tar
[root@loongson portainer]# tar xf loongson-portainer.tar
8.经分析,需要重新编译的二进制文件为portainer
[root@loongson portainer]# file portainer portainer: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
接下来,从github下载portainer源代码,重新编译portainer
二、从github下载portainer源代码
1.设置GO语言参数—GOPATH
export GOPATH=/usr/share/gocode
2.使用go get 从github中下载源代码
[root@loongson portainer]# go get github.com/portainer/portainer package github.com/portainer/portainer: no buildable Go source files in /usr/share/gocode/src/github.com/portainer/portainer
这里出现了错误提示,但是没有关系,go get 命令相当于先下载,再安装两个步骤,上面的提示是安装失败,我们需要的是源代码,因此可以忽略此提示
3.打开源代码所在文件夹
[root@loongson portainer]# cd $GOPATH/src/github.com/portainer/portainer
4.因为只需要编译源代码中的api部分所以将此文件夹下的其他内容全部删除
[root@loongson portainer]# rm -rf app assets bower.json build build.sh codefresh.yml CODE_OF_CONDUCT.md CONTRIBUTING.md gruntfile.js index.html LICENSE package.json README.md test vendor.yml distribution
5.因为go语言文件中的的目录的相对路径和源代码中的相对路径不同,所以需要对源代码的相对路径做调整
[root@loongson portainer]# cp -rf api/* $GOPATH/src/github.com/portainer/portainer
6.删除源代码中的api文件夹
[root@loongson portainer]# rm -rf api/
三、编译portainer源代码
1.打开main.go所在目录
[root@loongson portainer]# cd $GOPATH/src/github.com/portainer/portainer/cmd/portainer
2.执行go build 命令,开始进行代码编译
[root@loongson portainer]# go build main.go ../../../../../gopkg.in/alecthomas/kingpin.v2/usage.go:10:2: cannot find package "github.com/alecthomas/template" in any of: /usr/lib/golang/src/github.com/alecthomas/template (from $GOROOT)
3.根据提示需要加载github.com/alecthomas/template
[root@loongson portainer]# go get github.com/alecthomas/template
4.再次执行go build 命令,开始进行代码编译
[root@loongson portainer]# go build main.go ../../../../../gopkg.in/alecthomas/kingpin.v2/parsers.go:9:2: cannot find package "github.com/alecthomas/units" in any of: /usr/lib/golang/src/github.com/alecthomas/units (from $GOROOT) /usr/share/gocode/src/github.com/alecthomas/units (from $GOPATH)
5.根据提示需要加载github.com/alecthomas/units
[root@loongson portainer]# go get github.com/alecthomas/units
6.再次执行go build 命令,开始进行代码编译
[root@loongson portainer]# go build main.go ../../http/handler/auth.go:11:2: cannot find package "github.com/asaskevich/govalidator" in any of: /usr/lib/golang/src/github.com/asaskevich/govalidator (from $GOROOT) /usr/share/gocode/src/github.com/asaskevich/govalidator (from $GOPATH)
7.根据提示需要加载github.com/asaskevich/govalidator
[root@loongson portainer]# go get github.com/asaskevich/govalidator
8.再次执行go build 命令,开始进行代码编译
[root@loongson portainer]# go build main.go ../../bolt/datastore.go:8:2: cannot find package "github.com/boltdb/bolt" in any of: /usr/lib/golang/src/github.com/boltdb/bolt (from $GOROOT) /usr/share/gocode/src/github.com/boltdb/bolt (from $GOPATH)
9.根据提示需要加载github.com/boltdb/bolt
[root@loongson portainer]# go get github.com/boltdb/bolt # github.com/boltdb/bolt ../../../../boltdb/bolt/db.go:101: undefined: maxMapSize ../../../../boltdb/bolt/db.go:101: invalid array bound maxMapSize
10.根据提示缺少变量maxMapSize,那么接下来创建变量,首先打开boltdb所在目录
[root@loongson portainer]# cd $GOPATH/src/github.com/boltdb/bolt
11.创建适用于mips64el平台的bolt
[root@loongson bolt]# cp bolt_amd64.go bolt_mips64el.go
12.打开main.go所在目录
[root@loongson bolt]# cd $GOPATH/src/github.com/portainer/portainer/cmd/portainer/
13.再次执行go build 编译文件
[root@loongson portainer]# go build main.go ../../jwt/jwt.go:9:2: cannot find package "github.com/dgrijalva/jwt-go" in any of: /usr/lib/golang/src/github.com/dgrijalva/jwt-go (from $GOROOT) /usr/share/gocode/src/github.com/dgrijalva/jwt-go (from $GOPATH)
14.根据提示需要加载github.com/dgrijalva/jwt-go
[root@loongson portainer]# go get github.com/dgrijalva/jwt-go
15.再次执行go build 命令,开始进行代码编译
[root@loongson portainer]# go build main.go ../../http/handler/auth.go:12:2: cannot find package "github.com/gorilla/mux" in any of: /usr/lib/golang/src/github.com/gorilla/mux (from $GOROOT) /usr/share/gocode/src/github.com/gorilla/mux (from $GOPATH)
16.根据提示需要加载github.com/gorilla/mux
[root@loongson portainer]# go get github.com/gorilla/mux
17.再次执行go build 命令,开始进行代码编译
[root@loongson portainer]# go build main.go ../../jwt/jwt.go:10:2: cannot find package "github.com/gorilla/securecookie" in any of: /usr/lib/golang/src/github.com/gorilla/securecookie (from $GOROOT) /usr/share/gocode/src/github.com/gorilla/securecookie (from $GOPATH)
18.根据提示需要加载github.com/gorilla/securecookie
[root@loongson portainer]# go get github.com/gorilla/securecookie
19.再次执行go build 命令,开始进行代码编译
[root@loongson portainer]# go build main.go ../../http/proxy/manager.go:7:2: cannot find package "github.com/orcaman/concurrent-map" in any of: /usr/lib/golang/src/github.com/orcaman/concurrent-map (from $GOROOT) /usr/share/gocode/src/github.com/orcaman/concurrent-map (from $GOPATH)
20.根据提示需要加载github.com/orcaman/concurrent-map
[root@loongson portainer]# go get github.com/orcaman/concurrent-map
21.再次执行go build 命令,开始进行代码编译
[root@loongson portainer]# go build main.go ../../cron/watcher.go:5:2: cannot find package "github.com/robfig/cron" in any of: /usr/lib/golang/src/github.com/robfig/cron (from $GOROOT) /usr/share/gocode/src/github.com/robfig/cron (from $GOPATH)
22.根据提示需要加载github.com/robfig/cron
[root@loongson portainer]# go get github.com/robfig/cron
23.再次执行go build 命令,开始进行代码编译
[root@loongson portainer]# go build main.go ../../crypto/crypto.go:4:2: cannot find package "golang.org/x/crypto/bcrypt" in any of: /usr/lib/golang/src/golang.org/x/crypto/bcrypt (from $GOROOT) /usr/share/gocode/src/golang.org/x/crypto/bcrypt (from $GOPATH) ../../http/handler/websocket.go:21:2: cannot find package "golang.org/x/net/websocket" in any of: /usr/lib/golang/src/golang.org/x/net/websocket (from $GOROOT) /usr/share/gocode/src/golang.org/x/net/websocket (from $GOPATH)
24.根据提示需要加载golang.org/x/crypto/bcrypt和golang.org/x/net/websocket
注意:$GOPATH的路径已经不再是/usr/share/gocode/src/github.com/...
而是/usr/share/gocode/src/golang.org/x/...
所以需要先创建文件夹
[root@loongson portainer]# mkdir -p $GOPATH/src/golang.org/x/
25.切换至该文件夹下
[root@loongson portainer]# cd $GOPATH/src/golang.org/x/
26.加载golang.org/x/crypto/bcrypt
[root@loongson x]# git clone https://github.com/golang/crypto.git
27.加载golang.org/x/net/websocket
[root@loongson x]# git clone https://github.com/golang/net.git
28.切换至main.go所在目录
[root@loongson x]# cd $GOPATH/src/github.com/portainer/portainer/cmd/portainer/
29.再次执行go build 命令,开始进行代码编译
[root@loongson portainer]# go build main.go
30.编译完成,当前目录生成文件名为main的二进制可执行文件,下面需要拷贝到loongson-portainer.tar 解压目录,替换掉二进制文件portainer
四、loongson-portainer.tar二进制文件替换
1.修改编译完成后二进制文件的文件名
[root@loongson portainer]# mv main portainer
2.拷贝loongson-portainer.tar 解压目录,替换掉二进制文件portainer
[root@loongson portainer]# cp -f portainer /root/portainer/
3.切换至loongson-portainer.tar 解压目录
[root@loongson portainer]# cd /root/portainer/
4.运行二进制文件portainer
[root@loongson portainer]# ./portainer
5.打开浏览器,输入网址http://localhost:9000
6.切换至loongson-portainer.tar 解压目录的上级目录
[root@loongson portainer]# cd /root/
7.压缩整个portainer文件夹
[root@loongson ~]# tar -cvf portainer.tar portainer/
五、制作portainer镜像
1.在loongnix上下载fedora21-tools基础镜像
[root@loongson ~]# docker pull docker.io/huangxg20171010/feodra21-tools REPOSITORY TAG docker.io/huangxg20171010/fedora21-tools latest
2.运行feodra21-tools基础镜像
[root@loongson ~]# docker run -i -t docker.io/huangxg20171010/fedora21-tools
3.基础镜像运行成功后,会自动进入镜像控制台,由[root@loongson ~]变成[root@1cb98e167e49 /],说明容器创建成功,下面切换目录至root下
[root@1cb98e167e49 /]# cd /root/
4.将第四节第7步压缩的portainer.tar拷贝到当前容器的root目录下
[root@1cb98e167e49 ~]# scp [email protected]:/root/portainer.tar /root/
5.将portainer.tar解压到当前目录
[root@1cb98e167e49 ~]# tar xvf portainer.tar
6.删除压缩文件portainer.tar
[root@1cb98e167e49 ~]# rm -f portainer.tar
7.切换至portainer目录下
[root@1cb98e167e49 ~]# cd /root/portainer
8.创建执行文件run-portainer.sh
[root@1cb98e167e49 ~]# vi /root/portainer/run-portainer.sh
9.run-portainer.sh文件内容如下
#!/bin/bash export LC_ALL=zh_CN.UTF-8 export LANG=zh_CN.UTF-8 cd /root/portainer ./portainer
10.修改run-portainer.sh文件权限
[root@1cb98e167e49 ~]#chmod +x /root/portainer/run-portainer.sh
11.创建portainer所需文件夹
[root@1cb98e167e49 ~]#mkdir -p /data/tls
12.退出当前容器
[root@1cb98e167e49 ~]# exit
13.展示所有已创建容器
[root@loongson /]# docker ps -a CONTAINER IMAGE 1cb.... docker.io/huangxg20171010/fedora21-tools
14.使用Docker commit生成一个新镜像
[root@loongson /]# docker commit --change='CMD ["/root/portainer/run-portainer.sh"]' 1cb98e167e49 portainer
15.查看制作的新镜像
[root@loongson /]# docker images REPOSITORY TAG IMAGE ID CREATED portainer latest 085a675a35d7 12 seconds ago
六、上传portainer镜像
1.申请docker hub 帐号
打开 docker hub官网:https://hub.docker.com 进行注册
2.邮件激活后登录docker hub 点击 Create --> Create repository 创建一个仓库
3.本机登录Docker hub帐号
[root@loongson /]# docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: jiangxinshang Password: Login Succeeded
4.将本机已经存在的镜像名称做格式化,保证和仓库名称:jiangxinshang/portainer 一致,操作如下:
[root@loongson /]# docker tag portainer:latest jiangxinshang/portainer
5.使用 docker push 将镜像上传至hub上,操作如下:
[root@loongson /]# docker push jiangxinshang/portainer The push refers to a repository [docker.io/jiangxinshang/portainer] 572868387250: Pushed
6.查看所上传镜像
[root@loongson /]# docker search jiangxinshang/portainer
七、下载并运行portainer镜像
1.下载portainer镜像
[root@loongson /]# docker pull jiangxinshang/portainer
2.查看已下载镜像
[root@loongson /]# docker images REPOSITORY TAG docker.io/jiangxinshang/portainer latest
3.运行该镜像
[root@loongson /]# docker run -i -t --name portainer -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock docker.io/jiangxinshang/portainer
4.打开浏览器,输入网址http://localhost:9000
==================================================================================
X86版本的portainer官方镜像docker.io/portainer/portainer 已更新版本,可通过docker pull portainer/portainer:1.14.3来获取镜像,portainer的github源代码请下载版本v1.14.3
文章更新日期:2017年10月24日