Ubuntu安裝 Docker

安裝前準(zhǔn)備

  • 查看自己的操作系統(tǒng)
# 命令行輸入,查看ubuntu 內(nèi)核版本
$ uname -a
Linux instance 4.15.0-66-generic 
#75-Ubuntu SMP Tue Oct 1 
05:24:09 UTC                                        
2019 x86_64 x86_64 x86_64 GNU/Linux

輸入命令后可以看到內(nèi)核版本4.15.0-66,系統(tǒng)x86_64

  • 卸載舊版本,如果以前安裝過(guò)的話(huà)
$ sudo apt-get remove docker docker-engine docker.io containerd runc
  • 使用官網(wǎng)提供的倉(cāng)庫(kù)安裝
    首次在新主機(jī)上安裝社區(qū)版之前,需要設(shè)置Docker存儲(chǔ)庫(kù)。之后,您可以從存儲(chǔ)庫(kù)安裝和更新Docker。
    • 設(shè)置倉(cāng)庫(kù)源
  # 1. 更新apt索引
  $ sudo apt-get update
  # 2. Install packages to allow apt to use a repository over HTTPS:
  $ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
  # 3. 添加Docker的官方GPG密鑰,
  # 添加完秘鑰后會(huì)顯示OK,然后驗(yàn)證是否一致 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
  $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  $ sudo apt-key fingerprint 0EBFCD88
# 使用以下命令設(shè)置穩(wěn)定倉(cāng)庫(kù)。
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

正式開(kāi)始安裝Docker社區(qū)版

INSTALL DOCKER ENGINE - COMMUNITY

  • 更新apt索引
sudo apt-get update
  • 直接安裝最新版本,或者直接到下一步安裝指定版本
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
  • 安裝docker指定版本

a. 列出你的倉(cāng)庫(kù)的所有的版本

$ apt-cache madison docker-ce
 docker-ce | 5:19.03.8~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.7~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.6~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.5~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:19.03.4~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 ...

b. 通過(guò)指定<VERSION_STRING>安裝制定版本,比如5:19.03.83-0ubuntu-bionic

$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

以上所有命令合集

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install     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 docker-ce docker-ce-cli containerd.io
docker -v

安裝成功

  • 運(yùn)行hello world映像,驗(yàn)證Docker Engine-Community是否正確安裝
    $ sudo docker run hello-world
    此命令下載測(cè)試映像并在容器中運(yùn)行它。當(dāng)容器運(yùn)行時(shí),它會(huì)打印一條信息性消息并退出。效果如下:
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 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 a new container 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.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

root@instance$ 

參考文獻(xiàn):
docker官網(wǎng) Get Docker Engine - Community for Ubuntu 2020/03/18

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容