UbuntuServer 1804.5安装Docker

Posted liy36

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UbuntuServer 1804.5安装Docker相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env bash
# Install Docker Engine.
__Author__="liy"

path="$(dirname ${0})"
logfile=${1:-"${path}/install.log"}


: \'print log info.\'
function printlog(){
        datetime="$(date \'+%F %T\')"
        echo -e "\\033[32m[${datetime}] $1\\033[0m" |tee -a ${logfile}
}

function install(){
        if [ $UID == "0" ];then 
                printlog "Start install Depend pack..."
                apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common -y  &>> ${logfile}
                printlog "Start install public key..."
                curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
                printlog "Start install Docker repository..."
                add-apt-repository "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"  &>> ${logfile}
                apt-get update &>> ${logfile}
                printlog "Start install Docker Engine..."
                apt-get install docker-ce=5:19.03.15~3-0~ubuntu-bionic docker-ce-cli=5:19.03.15~3-0~ubuntu-bionic -y &>> ${logfile}
                printlog "Start setting daemon.json file..."
                [ -d "/etc/docker" ] || mkdir /etc/docker
cat << EOF > /etc/docker/daemon.json
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
                printlog \'Update GRUB_CMDLINE_LINUX...\\nPlease Reboot...\'
                sed -Ei \'/GRUB_CMDLINE_LINUX=/s/(.*)"/\\1 cgroup_enable=memory swapaccount=1"/\' /etc/default/grub
                update-grub &>> ${logfile}
                printlog \'Disable Swap Partition... backup file in /etc/fstab.bak\'
                sed -i.bak \'/swap/s/^/#/\' /etc/fstab
                systemctl daemon-reload
                printlog "Setting Docker Starting UP..."
                systemctl enable docker
        else 
                echo -e "\\033[31mUse Root Exec $0...\\033[0m"
                exit 127
        fi
}

function main(){
        echo -e "\\033[31m${logfile} will be emptied after 3 seconds...\\033[0m"
        sleep 5
        echo > ${logfile}
        printlog "log output to ${logfile} and use tail -f to view..."
        install
}

main

以上是关于UbuntuServer 1804.5安装Docker的主要内容,如果未能解决你的问题,请参考以下文章

UbuntuServer 16.04 with LNMP搭建WordPress

2016-09-16UbuntuServer14.04或更高版本安装问题记录

如何安装ubuntu server

ubuntu server 安装Gnome桌面并设置开机boot到桌面

ubuntu server 安装Gnome桌面并设置开机boot到桌面

001-mac使用桌面Dock键盘程序安装