Docker私仓harbo安装使用

docker私仓harbo安装使用

安装docker

1
2
3
4
5
6
7
8
9
10
yum install -y yum-utils  device-mapper-persistent-data lvm2

# 配置repository:
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# 安装最新版本docker-ce
yum install docker-ce

# 启动docker
systemctl start docker

安装docker-compose

1
2
3
4
5
6
7
8
9
10
# 安装pip
yum -y install python-pip

# 安装
pip install docker-compose

# 查看版本确认安装成功
[root@localhost ~]# docker-compose --version
docker-compose version 1.24.0, build 0aa5906

安装harbor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# github 选择版本下载https://github.com/goharbor/harbor/releases
wget -P /usr/loca/src/ https://github.com/vmware/harbor/releases/download/v1.2.0/harbor-online-installer-v1.2.0.tgz

cd /usr/local/src/
tar -zxvf harbor-online-installer-v1.2.0.tgz

# 配置文件 /usr/local/harbor/harbor.cfg
# 配置hostname ;hostname =192.168.0.101 #根据实际情况配置

# 添加docker国内镜像
# vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}

# 执行安装
./install.sh

查看进程

1
docker ps

启动、关闭、重启

1
2
3
4
5
6
启动Harbor
# docker-compose start
停止Harbor
# docker-comose stop
重启Harbor
# docker-compose restart

访问harbor

  • 使用安装之前配置的hostname访问
    1
    2
    # 默认账号密码:
    admin / Harbor12345

镜像测试

  • harbor中添加项目

  • 编写dockerFile vim Dockerfile

    1
    2
    3
    4
    5
    6
    7
    8
    9
    FROM alpine:latest
    MAINTAINER alex liuhaogui@gmail.com
    ENV TZ "Asia/Shanghai"
    # install nginx
    RUN apk --update add nginx

    EXPOSE 80

    CMD ["nginx", "-g", "daemon off;"]
  • 编译dockerFile

1
2
3
docker build -t 192.168.0.101/test/apline1:v0.1 .
#推送 ;推送前需先登录,见后docker login
docker push 192.168.0.101/test/apline1:v0.1
  • 测试拉取镜像 busybox
1
2
3
docker pull busybox
# 给busybox打个tag 推送私仓用
docker tag busybox:latest 192.168.0.101:80/test/busybox:latest

docker login

1
docker login 192.168.0.101

docker 推送测试

1
docker push 192.168.0.101/test/busybox:latest
  • 解决http私仓推送

    • registry-mirrors cdn加速
    • insecure-registries 私仓地址
      1
      2
      3
      4
      5
      6
      {
      "registry-mirrors": ["https://registry.docker-cn.com"]
      "insecure-registries": [
      "http://192.168.0.101"
      ]
      }
  • 登录harbor查看镜像是否存在

  • 删除本地镜像测试拉取

1
2
3
4
# 删除
docker rmi 192.168.0.101:80/test/busybox:latest
# 拉取测试
docker pull 192.168.0.101/test/busybox:latest

配置https

1
2
3
ui_url_protocol = https
ssl_cert = /data/addx/xxx.pem
ssl_cert_key = /data/addx/xxx.key