docker18.ce harbor 安裝

 Harbor 是什麼?css

harbor VMware 開發的一個容器鏡像倉庫,harbor的功能提供用戶權限管理、鏡像複製等功能,提升使用的registry的效率。linux

 

安裝最新版的docker能夠參考docker的官網nginx

https://docs.docker.com/install/linux/docker-ce/centos/git

1、安裝dockergithub

環境:centos7.5  2c2gweb

安裝依賴
sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

安裝源
 sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

查看docker版本

yum list docker-ce --showduplicates | sort -r

docker-ce.x86_64            3:18.09.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.1-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            18.06.3.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.2.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.1.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.0.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            18.03.0.ce-1.el7.centos            docker-ce-stable 

安裝docker
sudo yum install docker-ce-18.06.3.ce-3.el7

 

2、配置docker 加速sql

安裝好docker以後配置國內鏡像拉取,配置的文件是 /etc/docker/daemon.jsondocker

這個文件剛開始的時候是沒有的。須要手動建立。或者使用daocloud 上面配置 json

訪問:https://www.daocloud.io/mirror  拉倒最下面vim

查看Docker加速器

Linux :curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io

配置好了後重啓docker

systemctl  daemon-reload
systemctl  restart docker

 

3、配置harbor 鏡像倉庫

使用harbor鏡像倉庫的好處,圖形化界面,方便管理。

安裝harbor 咱們須要 安裝Docker Compose。

安裝docker compose 咱們仍是參考docker官方文檔 :https://docs.docker.com/compose/install/

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

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

 

下載harbor 安裝包

訪問:https://github.com/goharbor/harbor/releases
咱們能夠看到harbor的包有兩種,一種是offline(離線安裝),一種是online(在線安裝)。咱們選擇離線安裝。

wget https://storage.googleapis.com/harbor-releases/release-1.7.0/harbor-offline-installer-v1.7.4.tgz

解壓
tar -zxf harbor-offline-installer-v1.7.4.tgz

  

解壓完成後 進入harbor目錄,咱們只須要修改harbor.cfg文件中hostname,將reg.mydomain.com 換成你宿主機的IP地址

sed -i s'/reg.mydomain.com/192.168.1.200/' harbor.cfg

執行
./prepare
執行成功後
./install.sh

  

安裝完成後訪問宿主機IP地址。

默認用戶名密碼是:admin   Harbor12345

 配置docker鏡像倉庫

vim /etc/docker/daemon.json
{
 "registry-mirrors": ["http://f1361db2.m.daocloud.io"], #鏡像加速地址
 "insecure-registries": ["192.168.1.200"], #docker鏡像倉庫地址
}

重啓docker
systemctl daemon-reload
systemctl  restart docker

 

測試 

docker pull busybox

docker tag busybox:latest 192.168.1.200:80/library/busybox:v1

docker login 192.168.1.200:80  #登陸Harbor鏡像倉庫

docker push 192.168.1.200:80/library/busybox:v1 #推送鏡像到倉庫

  

4、鏡像安全

  harbor 若是放在公網上,通常都不要暴露使用默認端口,防止攻擊。

  一、修改docker-compose.yml文件映射爲1180端口:

proxy:
    image: goharbor/nginx-photon:v1.7.4
    container_name: nginx
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
      - NET_BIND_SERVICE
    volumes:
      - ./common/config/nginx:/etc/nginx:z
    networks:
      - harbor
    dns_search: .
    ports:
      - 1180:80
      - 443:443
      - 4443:4443
    depends_on:
      - postgresql
      - registry
      - core
      - portal
      - log

  

  只修改 docker-compose.yml文件 web頁面訪問正常,但docker login時,會出現問題  

[root@server ~]# docker login 192.168.1.200:1180
Username: admin
Password: 
Error response from daemon: Get http://192.168.1。200:1180/v2/: unable to decode token response: invalid character 'A' looking for beginning of value 

 二、修改common/templates/registry/config.yml 這個文件,將1180端口加入裏面

vim common/templates/registry/config.yml

auth:
  token:
    issuer: harbor-token-issuer
    realm: $public_url:1180/service/token
    rootcertbundle: /etc/registry/root.crt
    service: harbor-registry

  

 三、重啓harbor

docker-compose stop
 ./install.sh

 四、修改/etc/docker/daemon.json

{
  "registry-mirrors": ["http://f1361db2.m.daocloud.io"],
  "insecure-registries": ["192.168.1.200:1180"]
}

  五、重啓docker

systemctl daemon-reload
systemctl  restart docker

  六、從新打tag,推送harbor

 

docker tag busybox:latest 192.168.1.200:1180/library/busybox:v1
docker login 192.168.1.200:1180
docker push 192.168.1.200:1180/library/busybox:v1

查看web界面是否有此鏡像
相關文章
相關標籤/搜索