目的:為服務器安裝Docker Engine
- Shell內容
#!/bin/bash
function yellow(){
echo -e "\033[33m[$1]\033[0m"
}
yellow "---------安裝docker---------"
sudo apt-get update && \
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && \
sudo apt-key fingerprint 0EBFCD88 && \
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable" && \
sudo apt-get update && \
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose && \
yellow "---------一般使用者直接執行docker指令---------"
#創建一個docker群組
sudo groupadd docker
#把當前用戶添加到docker群組
sudo usermod -aG docker $USER
#newgrp docker刷新對docker群組的更改或是重新啟動虛擬機器
yellow "---------重新開機---------"
read -p 'do you want to reboot ? [Y/N]' inputs
if [ "$inputs"x == 'n'x ] || [ "$inputs"x == 'N'x ]
then
echo "Please reboot after other actions are completed"
else
sudo reboot
fi- 添加執行權限給shell檔:chmod +x <shell檔名>.sh
- 最後詢問重新開機,如果要立即重新開機輸入 y ,需要再執行其他作業輸入n
參考來源:
1.Install Docker Engine on Ubuntu
https://docs.docker.com/engine/install/ubuntu/
2.Post-installation steps for Linux
https://docs.docker.com/engine/install/linux-postinstall/
留言
張貼留言