zoukankan      html  css  js  c++  java
  • 【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之docker+docker compose

    目录

    1.【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之docker+docker compose(本篇在此)

    2.【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之gitlab + gitlab runner(docker in docker)

    3.【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之harbor 

    4.【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之gitlab runner 关于私有docker仓库配置 

    5.【系列】CentOS 7.3 离线安装(无网络环境)CI CD环境之sonarqube配置 

     

    网上有N多离线安装的教程,但都不是在无网络环境下安装 ,在这里我会记录在服务器无网络环境下离线安装CICD所需环境的完成过程

    1.docker + docker compose

    2.gitlab + gitlab runner (docker in docker)

    3.habor

    4.k8s

    本篇记录无网络环境安装docker+docker compse的过程

    首先下载离线docker 和docker compose离线安装包

    这里注意不要下载rpm离线安装包,因为会有可能因为系统中的包版本不对导致安装docker rpm 包时出现依赖错误,但由于服务器无法连接网络导致boom~

    docker 离线包下载地址:https://download.docker.com/linux/static/stable/

    docker compose 离线包下载地址:https://github.com/docker/compose/releases

    这里我下载的是docker-19.03.9版本

    1. 安装docker

    1.1 将离线包上传到服务器上,执行以下脚本:

    tar xzvf docker-19.03.9.tgz
    
    cp docker/* /usr/bin/
    
    dockerd &

    如果中途没有报错,则说明安装成功,可以用docker info 命令测试以下是否可以正常显示

    如果出现报错,则执行以下命令情况刚刚的安装,并重新执行1.中的脚本

    rm -rf /var/run/docker
    rm -rf /var/lib/docker
    rm -rf /var/run/docker.pid
    rm -rf /var/run/docker.sock文件
    ps -aux | grep docker
    停止docker相关进程
    netstat -nplt | grep docker
    解除docker相关进程占用端口

    1.2 设置docker为系统服务

    1.2.1 配置containerd

    命令如下:

    mkdir /etc/containerd
    containerd config default > /etc/containerd/config.toml
    touch /usr/lib/systemd/system/containerd.service
    vi /usr/lib/systemd/system/containerd.service

    containerd.service 内容如下:

    [Unit]
    Description=containerd container runtime
    Documentation=https://containerd.io
    After=network.target

    [Service]
    ExecStartPre=/sbin/modprobe overlay
    ExecStart=/usr/bin/containerd # 这是你 containerd 文件的放置路径
    Delegate=yes
    KillMode=process
    LimitNOFILE=1048576
    # Having non-zero Limit*s causes performance problems due to accounting overhead
    # in the kernel. We recommend using cgroups to do container-local accounting.
    LimitNPROC=infinity
    LimitCORE=infinity

    [Install]
    WantedBy=multi-user.target

    执行以下命令启动containerd服务并查看服务的状态:

    systemctl daemon-reload
    systemctl enable containerd.service
    systemctl start containerd.service
    systemctl status containerd.service

     1.2.2 配置docker.socket

    命令如下:

    groupadd docker
    touch /usr/lib/systemd/system/docker.socket
    vi /usr/lib/systemd/system/docker.socket

    docker.socket文件内容如下:

    [Unit]
    Description=Docker Socket for the API
    PartOf=docker.service

    [Socket]
    ListenStream=/var/run/docker.sock
    SocketMode=0660
    SocketUser=root
    # 如果出现错误:chown socket at step GROUP: No such process, 可以修改下面的 SocketGroup=root 或创建 docker 用户组(命令 groupadd docker)
    SocketGroup=docker

    [Install]
    WantedBy=sockets.target

    执行以下命令启动containerd服务并查看服务的状态:

    systemctl daemon-reload
    systemctl enable containerd.service
    systemctl start containerd.service
    systemctl status containerd.service
    1.2.3 配置docker.service服务

    执行以下命令:

    touch /usr/lib/systemd/system/docker.service
    vi /usr/lib/systemd/system/docker.service

    docker.service文件内容如下:

    [Unit]
    Description=Docker Application Container Engine
    Documentation=https://docs.docker.com
    BindsTo=containerd.service
    After=network-online.target firewalld.service containerd.service
    Wants=network-online.target
    Requires=docker.socket

    [Service]
    Type=notify
    # the default is not to use systemd for cgroups because the delegate issues still
    # exists and systemd currently does not support the cgroup feature set required
    # for containers run by docker
    ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
    ExecReload=/bin/kill -s HUP $MAINPID
    TimeoutSec=0
    RestartSec=2
    Restart=always

    # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
    # Both the old, and new location are accepted by systemd 229 and up, so using the old location
    # to make them work for either version of systemd.
    StartLimitBurst=3

    # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
    # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
    # this option work for either version of systemd.
    StartLimitInterval=60s

    # Having non-zero Limit*s causes performance problems due to accounting overhead
    # in the kernel. We recommend using cgroups to do container-local accounting.
    LimitNOFILE=infinity
    LimitNPROC=infinity
    LimitCORE=infinity

    # Comment TasksMax if your systemd version does not support it.
    # Only systemd 226 and above support this option.
    TasksMax=infinity

    # set delegate yes so that systemd does not reset the cgroups of docker containers
    Delegate=yes

    # kill only the docker process, not all processes in the cgroup
    KillMode=process

    [Install]
    WantedBy=multi-user.target

    在启动服务之前需要先对服务进行解禁操作,执行以下命令:

    systemctl unmask docker.service
    systemctl unmask docker.socket

    执行以下命令载入服务:

    chmod +x /usr/lib/systemd/system/docker.service
    systemctl daemon-reload
    systemctl enable docker
    systemctl start docker
    systemctl status docker

    如果出现启动docker失败,可以尝试重启服务器,我这里重启后docker状态就正常了

    2. 安装docker compose

    将docker compose 离线安装包上传至服务器,在安装包目录下执行以下命令:

    mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose 
    chmod +x /usr/local/bin/docker-compose
    docker-compose -v

     如出现docker-compose 命令不存在

     可执行下列命令,增加链接:

    sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

    到这里就安装完成了。

    参考:

    1. https://blog.csdn.net/ws995339251/article/details/90580258

    2. https://blog.csdn.net/catoop/article/details/102523847

  • 相关阅读:
    JS----事件
    JS----计时器
    JS----文档对象模型
    JS----基本数据类型
    JS----函数
    JS----数组
    JS----正则表达式
    CSS----盒子模型与浮动
    Web-9月13日随笔
    Web-9月14日随笔
  • 原文地址:https://www.cnblogs.com/c-supreme/p/offline-install-docker-and-docker-compse.html
Copyright © 2011-2022 走看看