docker私有仓库安装
一、docker register
安装docker 就不写了
1.拉镜像
docker pull registry
2.创建几个容器的本机映射文件位置 -- 初始化账户密码
/data/docker/registry //仓库 /data/docker/auth //普通验证 /data/docker/certs //https 签证存放
创建用户名和密码
//安装密码创建工具 yum install httpd-tools.x86_64 -y //cd /data/docker/auth 在auth目录下执行 当然你自己随便,记得改路径 >htpasswd -Bbn repoadmin 123456 > htpwd // 账户 repoadmin 密码 123456 //查看密文 cat htpwd repoadmin:$2y$05$lwg9eKXcjOveYAjuIgOqweBXRML508cUtl/6RY2xqNd1Eg6Sng4le
3.启动仓库
docker run -d -p 5000:5000 --restart=always --name registry -v /docker/data/registry:/var/lib/registry -v /data/docker/auth/:/auth -e "REGISTRY_AUTH=htpasswd" -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpwd" registry:latest
4.使用 客户端 docker配置
如下:没有则创建 -- 此处不创建会有问题,因为docker默认是https进行连接的,如果不通过该配置,则需要配置证书 cat /etc/docker/daemon.json { "insecure-registries": ["http://192.168.0.91:5000"] }
5.测试 登录
登录命令 可以先查询下
docker]# docker login --help Usage: docker login [OPTIONS] [SERVER] Log in to a registry. If no server is specified, the default is defined by the daemon. Options: -p, --password string Password --password-stdin Take the password from stdin -u, --username string Username 如上所示 docker login -u repoadmin -p 123456 192.168.0.91:5000 会提示保存到本地 测试: 1. docker pull nginx:1.18.0 从docker 源下载一个nginx 2. docker tag nginx:1.18.0 192.168.0.91:5000/nginx:1.18.0 打包一个tag -- 192.168.0.91:5000/nginx:1.18.0 3. docker push 192.168.0.91:5000/nginx:1.18.0 推送到私有仓库 4.到仓库服务器查看对应目录 -- 可以看到已经推送到私有仓库 tree registry/ registry/ └── docker └── registry └── v2 ├── blobs │ └── sha256 │ ├── 03 │ │ └── 03f221d9cf00a7077231c6dcac3c95182727c7e7fd44fd2b2e882a01dcda2d70 │ │ └── data │ ├── 0b │ │ └── 0b20d28b5eb3007f70c43cdd8efcdb04016aa193192e5911cda5b7590ffaa635 │ │ └── data │ ├── 15 │ │ └── 1576642c97761adf346890bf67c43473217160a9a203ef47d0bc6020af652798 │ │ └── data │ ├── 9b │ │ └── 9b0fc8e09ae1abb0144ce57018fc1e13d23abd108540f135dc83c0ed661081cf │ │ └── data │ ├── c1 │ │ └── c12a848bad84d57e3f5faafab5880484434aee3bf8bdde4d519753b7c81254fd │ │ └── data │ ├── c2 │ │ └── c2c45d506085d300b72a6d4b10e3dce104228080a2cf095fc38333afe237e2be │ │ └── data │ └── f7 │ └── f7ec5a41d630a33a2d1db59b95d89d93de7ae5a619a3a8571b78457e48266eba │ └── data └── repositories └── nginx ├── _layers │ └── sha256 │ ├── 03f221d9cf00a7077231c6dcac3c95182727c7e7fd44fd2b2e882a01dcda2d70 │ │ └── link │ ├── 0b20d28b5eb3007f70c43cdd8efcdb04016aa193192e5911cda5b7590ffaa635 │ │ └── link │ ├── 1576642c97761adf346890bf67c43473217160a9a203ef47d0bc6020af652798 │ │ └── link │ ├── c12a848bad84d57e3f5faafab5880484434aee3bf8bdde4d519753b7c81254fd │ │ └── link │ ├── c2c45d506085d300b72a6d4b10e3dce104228080a2cf095fc38333afe237e2be │ │ └── link │ └── f7ec5a41d630a33a2d1db59b95d89d93de7ae5a619a3a8571b78457e48266eba │ └── link ├── _manifests │ ├── revisions │ │ └── sha256 │ │ └── 9b0fc8e09ae1abb0144ce57018fc1e13d23abd108540f135dc83c0ed661081cf │ │ └── link │ └── tags │ └── 1.18.0 │ ├── current │ │ └── link │ └── index │ └── sha256 │ └── 9b0fc8e09ae1abb0144ce57018fc1e13d23abd108540f135dc83c0ed661081cf │ └── link └── _uploads 5.客户端下载 5.1 [root@localhost docker]# docker images //查看当前镜像 nginx 1.18.0 c2c45d506085 23 months ago 133MB 192.168.0.91:5000/nginx 1.18.0 c2c45d506085 23 months ago 133MB 5.2 [root@localhost docker]# docker rmi 192.168.0.91:5000/nginx:1.18.0 //删除tag的nginx 5.3 [root@localhost docker]# docker images //查看镜像 REPOSITORY TAG IMAGE ID CREATED SIZE nginx 1.18.0 c2c45d506085 23 months ago 133MB 5.4 [root@localhost docker]# docker pull 192.168.0.91:5000/nginx:1.18.0 //从私有仓库拉取镜像 5.5 [root@localhost docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.0.91:5000/nginx 1.18.0 c2c45d506085 23 months ago 133MB nginx 1.18.0 c2c45d506085 23 months ago 133MB //ok以上没有问题了
二、harbor 私有仓库安装
1、依赖
yum install docker-compose-plugin 软件包 docker-compose-plugin-2.16.0-1.el7.x86_64 已安装并且是最新版本 发现已经安装了 yum list all | grep docker 查看docker相关 docker-compose-plugin.x86_64 2.16.0-1.el7 @docker-ce-stable docker-compose version 命令发现不存在。 官网下载https://github.com/docker/compose/releases 我用这玩意了,先试试docker-compose-linux-armv6 如官方说明 Rename the relevant binary for your OS to docker-compose and copy it to $HOME/.docker/cli-plugins Or copy it into one of these folders to install it system-wide: /usr/local/lib/docker/cli-plugins OR /usr/local/libexec/docker/cli-plugins /usr/lib/docker/cli-plugins OR /usr/libexec/docker/cli-plugins (might require making the downloaded file executable with chmod +x) 还是用docker-compose-linux-x86_64 这个吧,上面那个不是 命令: chmod +x docker-compose-linux-x86_64 mv docker-compose-linux-x86_64 /usr/local/sbin/docker-compose docker-compose version Docker Compose version v2.15.1 这种方式下载也行 curl -SL https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
2.配置harbor.yml
cp harbor.yml.tmpl harbor.yml 修改: 1.访问端口 http: # port for http, default is 80. If https enabled, this port will redirect to https port port: 80 2.注掉https -- 因为自己用的,而且证书比较麻烦 #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 3.登录用户admin密码 harbor_admin_password: Harbor12345 4.存储卷 data_volume: /data
3.安装
./install.sh [Step 0]: checking if docker is installed ... Note: docker version: 23.0.1 [Step 1]: checking docker-compose is installed ... Note: Docker Compose version v2.16.0 d635f8a69c64: Loading layer [==================================================>] 37.73MB/37.73MB f9848e7e8e92: Loading layer [==================================================>] 5.758MB/5.758MB eeef8189f3c8: Loading layer [==================================================>] 8.733MB/8.733MB 。。。。 prepare base dir is set to /home/soft/harbor 。。。。 Clean up the input dir Note: stopping existing Harbor instance ... 。。。。。。 [+] Running 10/10 ⠿ Network harbor_harbor Created 0.2s ⠿ Container harbor-log Started 1.5s ⠿ Container registryctl Started 3.4s ⠿ Container registry Started 3.4s ⠿ Container harbor-db Started 3.0s ⠿ Container harbor-portal Started 2.6s ⠿ Container redis Started 3.3s ⠿ Container harbor-core Started 3.8s ⠿ Container harbor-jobservice Started 4.9s ⠿ Container nginx Started 4.9s ✔ ----Harbor has been installed and started successfully.----
4.访问
登录
5.停止与启动harbor
[root@localhost harbor]# docker-compose down [+] Running 10/10 ⠿ Container nginx Removed 0.4s ⠿ Container harbor-jobservice Removed 0.4s ⠿ Container registryctl Removed 10.3s ⠿ Container harbor-portal Removed 0.3s ⠿ Container harbor-core Removed 0.4s ⠿ Container harbor-db Removed 0.4s ⠿ Container registry Removed 0.3s ⠿ Container redis Removed 0.5s ⠿ Container harbor-log Removed 10.3s ⠿ Network harbor_harbor Removed [root@localhost harbor]# docker-compose up -d [+] Running 10/10 ⠿ Network harbor_harbor Created 0.2s ⠿ Container harbor-log Started 0.9s ⠿ Container harbor-portal Started 2.3s ⠿ Container registryctl Started 2.8s ⠿ Container harbor-db Started 2.7s ⠿ Container registry Started 2.6s ⠿ Container redis Started 2.7s ⠿ Container harbor-core Started 3.2s ⠿ Container nginx Started 4.5s ⠿ Container harbor-jobservice Started
6.harbor 应用
控制台 新建cicd项目
客户机配置
//配置私有仓库地址 这里因为没有https所以必须手动配置 insecure-registries cd /etc/docker/ touch daemon.json { "insecure-registries": ["http://192.168.0.92"] } //加载daemon systemctl daemon-reload //重启docker systemctl restart docker //登录 docker login -u admin -p Harbor12345 192.168.0.92 WARNING! Your password will be stored unencrypted in /root/.docker/config.json. docker pull nginx:1.18.0 //拉去一个nginx镜像 docker tag nginx:1.18.0 192.168.0.92/cicd/nginx:my_1.18.0 //打一个tag 版本号my_1.18.0 docker push 192.168.0.92/cicd/nginx:my_1.18.0 // 推送tag到私有仓库 //当前本地镜像 docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry latest 0d153fadf70b 5 weeks ago 24.2MB rancher/rancher latest fd4a6cdcb28f 8 weeks ago 1.62GB 192.168.0.92/cicd/nginx my_1.18.0 c2c45d506085 23 months ago 133MB nginx 1.18.0 c2c45d506085 23 months ago 133MB rancher/rancher v2.5.7 3ea53a0e3b90 2 years ago 1.01GB //删除本地tag镜像 docker rmi 192.168.0.92/cicd/nginx:my_1.18.0 //拉取tag镜像 docker pull 192.168.0.92/cicd/nginx:my_1.18.0 my_1.18.0: Pulling from cicd/nginx Digest: sha256:9b0fc8e09ae1abb0144ce57018fc1e13d23abd108540f135dc83c0ed661081cf Status: Downloaded newer image for 192.168.0.92/cicd/nginx:my_1.18.0 192.168.0.92/cicd/nginx:my_1.18.0 //再次查看本地镜像 docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry latest 0d153fadf70b 5 weeks ago 24.2MB rancher/rancher latest fd4a6cdcb28f 8 weeks ago 1.62GB 192.168.0.92/cicd/nginx my_1.18.0 c2c45d506085 23 months ago 133MB nginx 1.18.0 c2c45d506085 23 months ago 133MB rancher/rancher v2.5.7 3ea53a0e3b90 2 years ago 1.01GB
完事
乐享:知识积累,快乐无限。