卸載版本的docker
sudo apt-getremove docker docker-engine docker.io
安裝可選內(nèi)核模塊
從 Ubuntu 14.04 開始,一部分內(nèi)核模塊移到了可選內(nèi)核模塊包 ( linux-image-extra-* ) ,以
減少內(nèi)核軟件包的體積。正常安裝的系統(tǒng)應(yīng)該會(huì)包含可選內(nèi)核模塊包,而一些裁剪后的系統(tǒng)
可能會(huì)將其精簡(jiǎn)掉。 AUFS 內(nèi)核驅(qū)動(dòng)屬于可選內(nèi)核模塊的一部分,作為推薦的 Docker 存儲(chǔ)層
驅(qū)動(dòng),一般建議安裝可選內(nèi)核模塊包以使用 AUFS 。如果沒有安裝的話可以使用下面的命令安裝
sudo apt-getupdatesudo apt-getinstalllinux-image-extra-$(uname -r)? linux-image-extra-virtual
安裝Docker CE
由于 apt 源使用 HTTPS 以確保軟件下載過程中不被篡改。因此,我們首先需要添加使用
HTTPS 傳輸?shù)能浖约?CA 證書。
sudo apt-getupdatesudo apt-getinstall\? ? apt-transport-https \? ? ca-certificates \? ? curl \? ? software-properties-common
鑒于國內(nèi)網(wǎng)絡(luò)問題,強(qiáng)烈建議使用國內(nèi)源,官方源請(qǐng)?jiān)谧⑨屩胁榭?。為了確認(rèn)所下載軟件包的合法性,需要添加軟件源的 GPG 密鑰
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -# 官方源#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
然后,我們需要向 source.list 中添加 Docker 軟件源
sudo add-apt-repository \"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \$(lsb_release -cs)\stable"# 官方源#? sudo add-apt-repository \# "deb [arch=amd64] https://download.docker.com/linux/ubuntu \# $(lsb_release -cs) \# stable
更新 apt 軟件包緩存,并安裝 docker-ce
sudo apt-getupdatesudo apt-getinstalldocker-ce
啟動(dòng)docker CE
sudo systemctl enable dockersudo systemctlstartdocker
測(cè)試安裝是否正確
sudo docker run hello-worldUnable to find image'hello-world:latest'locallylatest:Pulling from library/hello-worldca4f61b1923c:Pull completeDigest:sha256:445b2fe9afea8b4aa0b2f27fe49dd6ad130dfe7a8fd0832be5de99625dad47cdStatus:Downloaded newer imageforhello-world:latestHello from Docker!This message shows that your installation appears to be working correctly.To generatethismessage, Docker took the followingsteps:1.The Docker client contacted the Docker daemon.2.The Docker daemon pulled the"hello-world"image from the Docker Hub.? ? (amd64)3.The Docker daemon created anewcontainer from that image which runs the? ? executable that produces the output you are currently reading.4.The Docker daemon streamed that output to the Docker client, which sent it? ? to your terminal.Totrysomething more ambitious, you can run an Ubuntu containerwith:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free DockerID: https://cloud.docker.com/For more examples and ideas,visit: https://docs.docker.com/engine/userguide/
如果出現(xiàn)上述信息,說明安裝成功
鏡像加速
由于國外的鏡像有時(shí)候網(wǎng)絡(luò)訪問過慢,需要使用國內(nèi)的鏡像加速
對(duì)于使用 systemd 的系統(tǒng),請(qǐng)?jiān)?/etc/docker/daemon.json 中寫入如下內(nèi)容(如果文件不存
在請(qǐng)新建該文件)
{"registry-mirrors": ["https://registry.docker-cn.com"]}
之后重啟啟動(dòng)系統(tǒng)
sudosystemctl daemon-reloadsudo systemctl restart docker