1. 程式人生 > 其它 >搭建docker-harbor步驟

搭建docker-harbor步驟

一、下載並安裝配置docker (新版本已經到20.10.14)

wget -qO- https://get.docker.com | sh或者 yum -y install docker

推薦:yum install docker-ce

安裝新版本docker:
yum配置阿里源:
/etc/yum.repos.d/
用來放指定yum倉庫伺服器的檔案,命名成repo結尾
可以新建一個repo檔案或者直接修改CentOS-Base.repo
下面是清華大學映象倉庫配置
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

或者阿里雲Yum源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache

檢視docker 版本:yum list docker-ce --showduplicates | sort -r
另一種方式:
yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
# 設定 yum 源為 穩定的版本  
# 阿里的源,國內使用較快
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache
# 如果要安裝指定的版本
yum list docker-ce --showduplicates | sort -r
# 填入版本號到下面的命令(docker-ce-19.03.0-3.el7)
yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

# 安裝最新穩定版本 Docker CE
yum install docker-ce docker-ce-cli containerd.io 

設定開機自啟動:
systemctl enable docker

配置daemon.json裡面的映象倉庫:
vi /etc/docker/daemon.json
一個常用的配置例項如下:

{
"registry-mirrors":[
"https://d8b3zdiw.mirror.aliyuncs.com"
],
 
"insecure-registries": [
"https://ower.site.com"
],
}
然後重啟docker
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker
解決普通使用者需要sudo問題:
Got permission denied while trying to connect to the Docker daemon socket at
將使用者新增到docker使用者組可以將sudo去掉
sudo groupadd docker #新增docker使用者組
sudo gpasswd -a $USER docker #將登陸使用者加入到docker使用者組中
newgrp docker #更新使用者組
groups檢視當前使用者所在的使用者組

docker info 檢視是否配置好了

二、安裝docker-compose

Docker Compose 是 Docker 官方編排(Orchestration)專案之一,負責快速在叢集中部署分散式應用。Dockerfile 可以讓使用者管理一個單獨的應用容器;而 Compose 則允許使用者在一個模板(YAML 格式)中定義一組相關聯的應用容器(被稱為一個 project,即專案),例如一個 Web 服務容器再加上後端的資料庫服務容器等。根據docker的API編寫。但是是單獨的專案,所以需要單獨安裝。

下載命令:

 curl -L https://github.com/docker/compose/releases/download/1.13.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

然後:chmod a+x /usr/local/bin/docker-compose

docker-compose --version 看版本

docker-compose version 1.13.0, build 1719ceb

 低版本不相容harbor,需要高版本:

curl -L https://github.com/docker/compose/releases/download/1.27.4/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose

 

三、安裝harbor

離線下載和線上安裝兩種

這裡用的離線下載:

https://github.com/goharbor/harbor/releases/download/v2.5.0/harbor-offline-installer-v2.5.0.tgz

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

cp harbor.yml.tmpl harbor.yml

vi harbor.yml

加上:harbor_admin_password: harbor123456

然後:./install.sh