Eli's Blog

1. 安装Docker

详见 Docker 安装

2. 安装Docker Compose

1
2
3
curl -L "https://github.com/docker/compose/releases/download/1.27.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose

3. 安装Harbor

下载地址:https://github.com/goharbor/harbor/releases

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
wget https://github.com/goharbor/harbor/releases/download/v2.0.2/harbor-offline-installer-v2.0.2.tgz

tar zxvf harbor-offline-installer-v2.0.2.tgz

mv harbor /usr/local/
cd /usr/local/harbor

cp harbor.yml.tmpl harbor.yml

vi harbor.yml
hostname: hub.elihe.io
https:
port: 443
# The path of cert and key files for nginx
certificate: /data/cert/server.crt
private_key: /data/cert/server.key

mkdir -p /data/cert && cd /data/cert

# 私钥
openssl genrsa -des3 -out server.key 2048

# 证书请求
openssl req -new -key server.key -out server.csr

# 备份私钥
cp server.key server.key.org

# 转换成证书 (去除设置的密码)
openssl rsa -in server.key.org -out server.key

# 签名
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt

# 证书赋予执行权限
chmod a+x *

# 安装harbor
cd /usr/local/harbor
./install.sh

# 启动 docker-compose
docker-compose start

# 开机启动 docker-compose
# 启动不一定成功,废弃
vi /etc/rc.d/rc.local
/usr/local/bin/docker-compose -f /usr/local/harbor/docker-compose.yml up -d

# 按这种方式
crontab -e
@reboot sleep 60 && /usr/local/bin/docker-compose -f /usr/local/harbor/docker-compose.yml up -d

4. Harbor服务器和客户端配置

1
2
3
4
5
6
7
8
9
10
11
# 添加域名解析
echo "192.168.31.200 hub.elihe.io" >> /etc/hosts

# 配置daemon.json
vi /etc/docker/daemon.json
{
"insecure-registries": ["https://hub.elihe.io"]
}

# 重启docker
systemctl daemon-reload && systemctl restart docker

5. 访问Harbor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
https://hub.elihe.io  admin/Harbor12345

docker login https://hub.elihe.io

docker pull nginx

docker tag nginx hub.elihe.io/library/nginx:v1

cat index.html
echo 'Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>' > index.html

cat > hostname.html <<EOF
<script type="text/javascript">
document.write(location.hostname);
</script>
EOF

docker commit 7e7553b2204f hub.elihe.io/library/nginx:v1

docker push hub.elihe.io/library/nginx:v1