minilabs

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

功能描述

在Amazon Linux 上自动安装Docker and Docker-compose

#!/bin/bash

# @Author : Lan Shiyun
# @Create Time : 2024/3/15
# @FileName : install_docker_4_aws_.sh
# @Version : 1.0
# @Software : VS Code
# @Update Time : 2024/3/15
# @UpdateBy : Lan Shiyun
# @Description : Shell script to install Docker and Docker Compose on Amazon Linux

# Main function to control the installation process
main() {
    # Check if Docker is already installed
    if ! command -v docker &> /dev/null; then
        echo "Installing Docker..."
        install_docker
    else
        echo "Docker is already installed."
    fi

    # Check if Docker Compose is already installed
    if ! command -v docker-compose &> /dev/null; then
        echo "Installing Docker Compose..."
        install_docker_compose
    else
        echo "Docker Compose is already installed."
    fi
}

# Function to install Docker
install_docker() {
    sudo yum update -y
    sudo amazon-linux-extras install docker -y
    sudo systemctl start docker
    sudo systemctl enable docker
    sudo usermod -aG docker $USER
}

# Function to install Docker Compose
install_docker_compose() {
    sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose
}

# Call the main function to start the installation process
main

posted on 2024-03-15 11:30  lanshiyun  阅读(27)  评论(0编辑  收藏  举报