반응형
도커 엔진 설치 스크립트(docker install script)
docker 설치
apt-get install -y dos2unix
curl -fsSL https://raw.githubusercontent.com/anti1346/zz/main/common/install_docker.sh | dos2unix | bash
docker-install.sh 스크립트 작성
vim docker-install.sh
#!/bin/bash
#### 운영체제 판단 및 업데이트
if command -v apt >/dev/null; then
# Debian 계열
echo "Linux Distribution: Debian"
apt update -qq -y >/dev/null 2>&1
apt install -qq -y lsb-release >/dev/null 2>&1
distro=$(lsb_release -ds | cut -d' ' -f1)
elif command -v yum >/dev/null; then
# RedHat 계열
echo "Linux Distribution: RedHat"
yum install -q -y redhat-lsb-core >/dev/null 2>&1
distro=$(lsb_release -ds | cut -d' ' -f1 | tr -d '"')
else
echo "Other OS"
exit 1
fi
### 운영체제 및 버전 추출
os_version=$(lsb_release -sr | cut -d'.' -f1)
### Docker 설치 여부 확인
if ! command -v docker >/dev/null; then
# Docker가 설치되어 있지 않다면 설치
if [ "$distro" == "CentOS" ] && [[ $os_version -eq 8 || $os_version -eq 7 ]]; then
# CentOS 7 또는 8
echo "CentOS $os_version"
curl -fsSL https://get.docker.com -o get-docker.sh
chmod +x get-docker.sh
bash get-docker.sh
usermod -aG docker $(whoami)
systemctl --now enable docker.service
elif [ "$distro" == "Amazon" ]; then
# Amazon Linux
echo "Amazon $os_version"
amazon-linux-extras install -y epel
amazon-linux-extras install -y docker
usermod -aG docker ec2-user
systemctl --now enable docker.service
elif [ "$distro" == "Ubuntu" ]; then
# Ubuntu
echo "Ubuntu $os_version"
apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update
apt install -y docker-ce
else
echo "Other OS"
exit 1
fi
else
echo "Docker is already installed."
fi
### 도커 컴포즈 설치
curl -fsSL "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
### CTOP 설치
CTOP_VERSION=${CTOP_VERSION:-0.7.7}
ctop_url="https://github.com/bcicen/ctop/releases/download/v${CTOP_VERSION}/ctop-${CTOP_VERSION}-linux-amd64"
curl -fsSL "$ctop_url" -o /usr/local/bin/ctop
chmod +x /usr/local/bin/ctop
ln -s /usr/local/bin/ctop /usr/bin/ctop
더보기
---
#!/bin/bash
### 운영체제 판단 및 업데이트 ###
if command -v apt >/dev/null; then
# Debian 계열
echo "Linux Distribution: Debian"
apt update -qq -y >/dev/null 2>&1
apt install -qq -y lsb-release >/dev/null 2>&1
distro=$(lsb_release -ds)
elif command -v yum >/dev/null; then
# RedHat 계열
echo "Linux Distribution: RedHat"
yum install -q -y redhat-lsb-core >/dev/null 2>&1
distro=$(lsb_release -ds | tr -d '"')
else
echo "Other OS"
exit 1
fi
# 운영체제 및 버전 추출
os_version=$(lsb_release -sr | cut -d'.' -f1)
### 도커 설치 ###
if [ "$distro" == "CentOS" ]; then
if [[ $os_version -eq 8 || $os_version -eq 7 ]]; then
# CentOS 7 또는 8
echo "CentOS $os_version"
curl -fsSL https://get.docker.com -o get-docker.sh
chmod +x get-docker.sh
bash get-docker.sh
usermod -aG docker $(whoami)
systemctl --now enable docker.service
elif [ "$distro" == "Amazon" ]; then
# Amazon Linux
echo "Amazon $os_version"
amazon-linux-extras install -y epel
amazon-linux-extras install -y docker
usermod -aG docker ec2-user
systemctl --now enable docker.service
elif [ "$distro" == "Ubuntu" ]; then
# Ubuntu
echo "Ubuntu $os_version"
apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update
apt install -y docker-ce
else
echo "Other OS"
exit 1
fi
fi
### 도커 컴포즈 설치 ###
curl -fsSL "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
### CTOP 설치 ###
CTOP_VERSION=${CTOP_VERSION:-0.7.7}
ctop_url="https://github.com/bcicen/ctop/releases/download/v${CTOP_VERSION}/ctop-${CTOP_VERSION}-linux-amd64"
curl -fsSL "$ctop_url" -o /usr/local/bin/ctop
chmod +x /usr/local/bin/ctop
ln -s /usr/local/bin/ctop /usr/bin/ctop
---
- Linux 배포판 및 아키텍처의 .deb 및 .rpm 패키지를 제공합니다.
참고URL
- docker docs : Install Docker Engine
728x90
반응형
'스크립트' 카테고리의 다른 글
[python] 파이썬 로또 번호 생성기 (0) | 2022.08.11 |
---|---|
python 모듈 탐색 경로 찾기 (0) | 2022.08.11 |
리눅스에서 운영체제 및 버전을 구분하는 스크립트 (0) | 2022.04.28 |
로컬 IP 및 공개 IP 찾는 방법(myip) (0) | 2022.04.06 |
데이터베이스(DB) 백업 스크립트 (0) | 2021.04.03 |