天天看点

二、Docker镜像私库Harbor搭建一、获取Harbor的安装包三、安装启动私服四、启动和关闭harbor服务

Docker镜像私库Harbor搭建

  • 一、获取Harbor的安装包
  • 三、安装启动私服
  • 四、启动和关闭harbor服务
为了方便微服务docker镜像的管理,在生产环境中基本都需要一个类似于docker.hub的docker镜像管理私库。

一、获取Harbor的安装包

harbor的Github开源地址:链接

获取其release版本的安装包:

在mac环境下选择如图的安装包并下载

二、Docker镜像私库Harbor搭建一、获取Harbor的安装包三、安装启动私服四、启动和关闭harbor服务

二、修改配置文件

解压安装包后,修改harbor.yml配置文件

因为没有使用https,所以这里吧响应的配置注释掉

# https related config
# https:
  # https port for harbor, default is 443
  # port: 443
  # The path of cert and key files for nginx
  # certificate: /your/certificate/path
  # private_key: /your/private/key/path
           

修改hostname 和 http对应的port

# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: hub.lh0811.com

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 5000
           

修改默认的harbor账号admin的密码

# Remember Change the admin password from UI after launching Harbor.
harbor_admin_password: 123456
           

修改数据挂载路径,为了方便管理 都挂载到当前目录下,

需要注意的是这里的路径需要写主机目录的绝对路径

# The default data volume
data_volume: /Users/lh0811/Desktop/server/harbor/data
# Log configurations
log:
  # options are debug, info, warning, error, fatal
  level: info
  # configs for logs in local storage
  local:
    # Log files are rotated log_rotate_count times before being removed. If count is 0, old versions are removed rather than rotated.
    rotate_count: 50
    # Log files are rotated only if they grow bigger than log_rotate_size bytes. If size is followed by k, the size is assumed to be in kilobytes.
    # If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes. So size 100, size 100k, size 100M and size 100G
    # are all valid.
    rotate_size: 200M
    # The directory on your host that store log
    location: /Users/lh0811/Desktop/server/harbor/var/log/harbor
           

三、安装启动私服

使用安装包中的install脚本

install.sh
           

需要注意的一点是 harbor目录中不能有中文

安装完成后 会在当前目录下生成一个docker-compose.yaml的描述文件。

以后就可以使用 docker-compose命令来启动和关闭harbor服务了

四、启动和关闭harbor服务

第三步安装成功后,在harbor的目录 会有docker-compose.yaml 文件

启动harbor服务
docker-compose up -d 

关闭harbor服务
docker-compose down
           

因为有数据挂载所以 只要挂载数据不被删除 数据都会持久化在本机,每次容器重启都会使用挂载数据恢复数据。