离线安装 Docker + Docker registry(Docker仓库)

概述

通过私有yum仓库安装docker

具体内容:

1. 构建私有镜像仓库

2. 准备rpm包

3. 安装部署

4. ansible 安装 + 卸载

5. shell 脚本安装 + 卸载

6. 网页连接

7. 构建docker 私有仓库

1. 构建私有镜像仓库

构建简单的yum私有仓库请参考如下文档

http://t.csdn.cn/22bmb

2. 准备rpm包

在构建docker私有镜像过程中,需要不断检测rpm的依赖关系。

详情请参考如下文档:

(46条消息) Linux 无网环境下离线安装rpm_HJJ-DREAMER的博客-CSDN博客

Packages for Linux and Unix - pkgs.org

# 查看系统版本,下载对应系统安装包
cat /etc/redhat-release
 
# 安装 yum 管理工具集
yum -y install yum-utils
 
# 添加 软件源信息
# 例如:
# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://url/software.repo
 
# 更新yum 仓库
yum clean all && yum makecache fast && yum repolist
# 或者 var/ftp/localrepo 是私有仓库地址
createrepo --update /var/ftp/localrepo && yum clean all && yum makecache && yum repolist
 
# 免安装下载rpm包
# 例如:
# yum install docker-ce --downloadonly --downloaddir=/var/ftp/localrepo/docker
yum install docker-ce --downloadonly --downloaddir=/foo
 
# 后期可以将所有的依赖和rpm包通过tar 压缩打包转存
tar -czvf software-rpm.tar.gz software

 阶段结果:

3. 安装部署

Install Docker Engine on CentOS | Docker Documentation文档进行安装部署

 install

# Uninstall old versions
sudo yum remove -y docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

# install
yum install docker-ce -y

# 启动服务
systemctl start docker
docker version

# 检测
docker run hello-world

报错 daemon 配置

假如没有设置daemon.json的镜像加速器,则会以下错误。

error parsing HTTP 408 response body 错误问题

过一段时间就可以重新执行成功

# 查看配置文件夹
ls /etc/docker/

# 配置镜像加速器
cat > /etc/docker/daemon.json << EOF
{
    "exec-opts": ["native.cgroupdriver=systemd"],
    "registry-mirrors": ["https://hub-mirror.c.163.com"],
    "insecure-registries":[]
}
EOF

# 重启服务
systemctl daemon-reload
systemctl restart docker

# 查看配置是否成功
docker info

 镜像加速器 · Docker -- 从入门到实践 (docker-practice.github.io)

docker国内镜像加速 - 知乎 (zhihu.com)

名字连接
docker中国区官方镜像加速:https://registry.docker-cn.com
网易镜像加速:http://hub-mirror.c.163.com
中国科技大学镜像加速:https://docker.mirrors.ustc.edu.cn
腾讯云镜像加速:https://mirror.ccs.tencentyun.com
阿里云镜像加速:https://ung2thfc.mirror.aliyuncs.com

4. ansible 安装

---
- name: update the ftp.repo
  hosts: k8s
  tasks:
    - name: scp the ftp.repo
      copy:
        src: /etc/yum.repos.d/ftp.repo
        dest: /etc/yum.repos.d/ftp.repo
        mode: "0644"
- name: install docker-ce
  hosts: k8s
  tasks:
    - name: update yum repo
      shell: yum clean all && yum makecache && yum repolist
    - name: stop the docker server
      systemd:
        name: docker
        state: stopped
      ignore_errors: True
    - name: remove the docker server
      yum:
        state: absent
        name: "{{ item }}"
      loop:
        - docker-ce
        - docker
        - docker-client
        - docker-client-latest
        - docker-common
        - docker-latest
        - docker-latest-logrotate
        - docker-logrotate
        - docker-engine
    - name: install the docker-ce
      yum:
        name: docker-ce
        state: present
    - name: update the daemon.json
      copy:
        src: ./daemon.json
        dest: /etc/docker/
        mode: "0644"
    - name: enable the docker server
      systemd:
        name: docker
        state: started
        enabled: yes
    - name: docker info
      shell: docker version && docker info

结果有2次

ansible-playbook ./docker-install/dockerinstall.yml

5. shell 脚本安装

#!/bin/bash
# init the env
function INIT_THE_ENV() {
    # 更新 yum 源
    yum clean all >> /dev/null && yum makecache fast >> /dev/null && yum repolist >> /dev/null
    
    # grep -o 表示:仅显示匹配到的字符串
    status=`systemctl status docker | grep -o  "running"`
    echo "docker status is $status"

    # 服务运行状态判断
    if [ $status = "running" ] 
    then
        echo "disable the docker server"
        systemctl disable --now docker
    else
        echo "dockers server is disable"
        # 否则继续执行程序
        continue
    fi

    # 卸载程序
    yum remove -y docker-ce \
                  docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine >> /dev/null

}

# install docker-ce
function INSTALL_THE_SRV() {

    yum install docker-ce -y  >> /dev/null

    systemctl start docker 
    status=`systemctl status docker | grep -o  "active (running)"`
    echo "docker is $status"
} 


echo "===init the env==="
INIT_THE_ENV

echo "===install docker==="
INSTALL_THE_SRV

6. 网页连接

docker-ce | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

Index of /docker-ce/linux/centos/7.9/x86_64/stable/Packages/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

Install Docker Engine on CentOS | Docker Documentation

Packages for Linux and Unix - pkgs.org

Index of linux/centos/7/x86_64/stable/Packages/ (docker.com)

7. docker 私有仓库构建

yum install -y docker-distribution
systemctl enable --now docker-distribution

curl http://127.0.0.1:5000/v2/_catalog

 ansible 统一配置

# 更新daemon.json
ansible k8s -m copy -a "src=/home/junjie/ansible/docker-install/daemon.json dest=/etc/docker/daemon.json mode=0644"
# 重启服务
ansible k8s -m systemd -a "name=docker daemon_reload=yes state=restarted"
#测试访问
ansible k8s -m shell -a "curl http://reporsitory:5000/v2/_catalog"
ansible k8s -m shell -a "curl http://192.168.164.16:5000/v2/_catalog"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值