搭建Docker私有仓库
前言:不断学习就是程序员的宿命
1、环境准备
服务器:centos7、内核5.6
内核升级:
yum update -y # 导入公钥 rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org # 安装7.x版本的ELRepo rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm # 安装新版本内核 yum --enablerepo=elrepo-kernel install kernel-lt -y Centos7.x 内核升级完毕后,需要修改内核的启动顺序 vim /etc/default/grub GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved #把这里的saved改成0 GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet net.ifnames=0" GRUB_DISABLE_RECOVERY="true"
运行grub2-mkconfig命令来重新创建内核配置,命令是grub2-mkconfig -o /boot/grub2/grub.cfg
,如下:
grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.17.171-1.el7.elrepo.x86_64 Found initrd image: /boot/initramfs-4.17.171-1.el7.elrepo.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-693.2.2.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-693.2.2.el7.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-f0f31005fb5a436d88e3c6cbf54e25aa Found initrd image: /boot/initramfs-0-rescue-f0f31005fb5a436d88e3c6cbf54e25aa.img done
2、服务端搭建
根据GitHub中issue:https://github.com/docker/distribution-library-image/issues/106,鄙人一直用最新的镜像,后续配置有问题,所以改用2.6.x
# 下载 registry docker pull registry:2.6.2 # 挂载相关的配置 mkdir -p /docker/registry/auth # 生成账号密码:msi msi123 docker run --entrypoint htpasswd registry:latest -Bbn msi msi123 >> /docker/registry/auth/htpasswd # 设置配置文件 mkdir -p /docker/registry/config vim /docker/registry/config/config.yml # 输入以下文件 version: 0.1 log: fields: service: registry storage: delete: enabled: true cache: blobdescriptor: inmemory filesystem: rootdirectory: /var/lib/registry http: addr: :5000 headers: X-Content-Type-Options: [nosniff] health: storagedriver: enabled: true interval: 10s threshold: 3 启动 docker run -d -p 5005:5000 --restart=always --name=registry \ -v /docker/registry/config/:/etc/docker/registry/ \ -v /docker/registry/auth/:/auth/ \ -e "REGISTRY_AUTH=htpasswd" \ -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \ -v /docker/registry/:/var/lib/registry/ \ registry:2.6.2
3、配置客户端
vim /etc/hosts 192.168.56.10 msi-registry ######登录 docker login 192.168.56.10:5005 # Error response from daemon: Get https://192.168.56.10:5005/v1/users/: dial tcp 192.168.56.10:5005: i/o timeout # 解决:https://blog.csdn.net/quanqxj/article/details/79479943 # Error response from daemon: Get https://192.168.56.10:5005/v2/: http: server gave HTTP response to HTTPS client # 解决: # vim /etc/docker/daemon.json # 添加如下内容 # {"insecure-registries":["msi-registry:5005","msi-registry"]}
参考:https://blog.csdn.net/shida_csdn/article/details/78435971