搜尋
首頁運維Dockercentos7下如何離線安裝docker和docker-compose

centos7下如何離線安裝docker和docker-compose

Sep 18, 2020 pm 04:41 PM
centos7dockerdocker-compose

centos7下如何離線安裝docker和docker-compose

具体安装步骤如下:

(推荐教程:docker教程

实测版本说明

  • centos:7.5

  • docker:19.03.5

  • docker-compose:1.24.3

官方资源下载地址

自行下载需要的版本。
[docker](https://download.docker.com/linux/static/stable/x86_64/)
[docker-compose](https://github.com/docker/compose/releases)

上传到服务器

上传 install-docker-offline.sh docker.service docker-ce docker-compose-Linux-x86_64压缩包到任意的同一文件夹下  
建议到/home

执行

sh install-docker-offline.sh

其他的根据脚本提示操作

install.sh

#!/bin/sh
echo -e '作者:Teler'
echo -e '版本:v0.0.1'
echo -e '创建时间:2020-02-02'
echo -e '更新时间:2020-02-02 22:21'

echo -e '给自己赋权限\n'
chmod +x ./$0

#初始化
function init(){
    clear
    echo -e '请选择操作\n'
    echo -e '1.安装docker\n'
    echo -e '2.安装docker-compose\n'
    echo -e 'exit:退出'
    
    call
} 

#决定调用什么方法
function call(){
    echo -e '\n'
    read -p '请输入:' INPUT
    case $INPUT in
        1)
        installDocker
        ;;
        2)
        installDockerCompose
        ;;
               
        *)
        #noFound
        echo '感谢使用........'
        exit
        ;;
    esac

    if [ $? -eq 0 ];then
        init
    fi 
}

#安装docker
function installDocker(){
    read -p '请输入完整的docker压缩包文件名:' FILENAME

    searchFile $FILENAME

    if [ $? -ne 0 ];then
        echo -e '\n文件不存在'
        installDocker
    fi

    echo -e '\n解压文件...'
    tar -xzvf $FILENAME
    if [ $? -eq 0 ];then
        echo -e '\n将docker目录移到/usr/bin目录下...'
        cp docker/* /usr/bin/
        if [ $? -ne 0 ];then
            echo -e '\n复制失败'
            exit
        fi
        echo -e '\n将docker.service 移到/etc/systemd/system/ 目录...'
        cp docker.service /etc/systemd/system/
        if [ $? -eq 0 ];then
            echo -e '\n添加文件权限...'
            chmod +x /etc/systemd/system/docker.service
            if [ $? -ne 0 ];then
                echo -e '\n添加失败'
                exit
            fi
            echo -e '\n重新加载配置文件...'
            systemctl daemon-reload
            if [ $? -ne 0 ];then
                echo -e '\n加载失败'
                exit
            fi
            echo -e '\n启动docker...'
            systemctl start docker
            if [ $? -ne 0 ];then
                echo -e '\n启动失败'
                exit
            fi
            echo -e '\n设置开机自启...'
            systemctl enable docker.service
            if [ $? -ne 0 ];then
                echo -e '\n开机启动失败'
                exit
            fi
            echo -e '\ndocker版本:'
            docker -v
        else
            echo -e '\n复制失败'
            exit
        fi
    else
        echo -e '\n解压失败'
        exit    
    fi
    return 0
}
#安装docker-compose
function installDockerCompose(){
    read -p '请输入完整的docker compose文件名:' FILENAME

    searchFile $FILENAME

    if [ $? -ne 0 ];then
        echo -e '\n文件不存在'
        installDockerCompose
    fi

    echo -e '\n复制文件到/usr/local/bin下 并重命名为docker-compose'
    cp -y $FILENAME /usr/local/bin/docker-compose
    if [ $? -ne 0 ];then
        echo -e '\n赋予执行权限'
        chmod +x /usr/local/bin/docker-compose

        echo '\ndocker-compose版本:'
        docker-compose -v
    else 
        echo '\n复制失败'
    fi


    return 0
}

#暂未支持
function noFound(){
    echo -e '暂未支持'
    return 0
}

#检查文件是否存在
#存在返回0 不存在返回1
function searchFile(){
    if [ -f "$1" ]; then
        return 0
    else 
        return 1
    fi
}




init

docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
 
[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
ExecReload=/bin/kill -s HUP $MAINPID
# 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
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# 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
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
 
[Install]
WantedBy=multi-user.target

以上是centos7下如何離線安裝docker和docker-compose的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:csdn。如有侵權,請聯絡admin@php.cn刪除
Docker和Linux:構建便攜式應用程序Docker和Linux:構建便攜式應用程序May 03, 2025 am 12:17 AM

如何利用Docker和Linux構建可移植的應用程序?首先,使用Dockerfile容器化應用,然後在Linux環境中管理和部署容器。 1)編寫Dockerfile,將應用及其依賴打包成鏡像。 2)使用dockerbuild和dockerrun命令在Linux上構建和運行容器。 3)通過DockerCompose管理多容器應用,定義服務依賴關係。 4)優化鏡像大小和資源配置,增強安全性,提升應用性能和可移植性。

Docker和Kubernetes:集裝箱編排的力量Docker和Kubernetes:集裝箱編排的力量May 02, 2025 am 12:06 AM

Docker和Kubernetes通過容器編排提升應用部署和管理效率。 1.Docker通過Dockerfile構建鏡像並運行容器,確保應用一致性。 2.Kubernetes通過Pod、Deployment和Service管理容器,實現自動化部署和擴展。

Docker vs. Kubernetes:主要差異和協同作用Docker vs. Kubernetes:主要差異和協同作用May 01, 2025 am 12:09 AM

Docker和Kubernetes是容器化和編排的領軍者。 Docker專注於容器生命週期管理,適合小型項目;Kubernetes則擅長容器編排,適用於大規模生產環境。兩者結合可提升開發和部署效率。

Docker and Linux:完美的合作夥伴關係Docker and Linux:完美的合作夥伴關係Apr 30, 2025 am 12:02 AM

Docker和Linux是完美的搭配,因為它們可以簡化應用的開發和部署流程。 1)Docker利用Linux的namespaces和cgroups實現容器隔離和資源管理。 2)Docker容器比虛擬機更高效,啟動速度快,鏡像分層結構便於構建和分發。 3)在Linux上,Docker的安裝和使用非常簡單,只需幾條命令即可。 4)通過DockerCompose,可以方便地管理和部署多容器應用。

Docker vs. Kubernetes:決定使用哪個Docker vs. Kubernetes:決定使用哪個Apr 29, 2025 am 12:05 AM

Docker和Kubernetes的區別在於:Docker是容器化平台,適合小型項目和開發環境;Kubernetes是容器編排系統,適合大型項目和生產環境。 1.Docker簡化應用部署,適用於資源有限的小型項目。 2.Kubernetes提供自動化和擴展能力,適用於需要高效管理的大型項目。

Docker和Kubernetes:構建可擴展應用程序Docker和Kubernetes:構建可擴展應用程序Apr 28, 2025 am 12:18 AM

使用Docker和Kubernetes可以構建可擴展的應用。 1)使用Dockerfile創建容器鏡像,2)通過kubectl命令部署Kubernetes的Deployment和Service,3)使用HorizontalPodAutoscaler實現自動擴展,從而構建高效、可擴展的應用架構。

Kubernetes和Docker:比較分析Kubernetes和Docker:比較分析Apr 27, 2025 am 12:05 AM

Docker和Kubernetes的主要區別在於:Docker用於容器化,Kubernetes用於容器編排。 1.Docker提供一致的環境來開發、測試和部署應用,通過容器實現隔離和資源限制。 2.Kubernetes管理容器化應用,提供自動化部署、擴展和管理功能,支持負載均衡和自動伸縮。兩者結合使用能提升應用的部署和管理效率。

在Linux上運行Docker:安裝和配置在Linux上運行Docker:安裝和配置Apr 26, 2025 am 12:12 AM

在Linux上安裝和配置Docker需要確保系統為64位且內核版本3.10及以上,使用命令“sudoapt-getupdate&&sudoapt-getinstalldocker-cedocker-ce-clicontainerd.io”安裝,並用“sudodockerrunhello-world”驗證。 Docker利用Linux內核的命名空間和控制組實現容器隔離和資源限制,鏡像是只讀模板,容器可進行修改。使用示例包括運行Nginx服務器和自定義Dockerfile創建鏡像。常見

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。