在 Ubuntu 中安装 docker


环境准备

检测版本

uname -a

版本号要大于 3.10

开始安装

首先,更新现有的软件包列表:

sudo apt-get update
sudo apt-get install apt

注意:如果无法更新,请先通过 Ubuntu or Debian 换源

接下来,安装一些必备软件包,让 apt 通过 HTTPS 使用软件包。

sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

此步骤非必要,部分版本无法识别此命令

然后将官方 Docker 版本库的 GPG 密钥添加到系统中:

curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

执行后显示 ok
检查密钥是否正确

sudo apt-key fingerprint 0EBFCD88  

此命令部分版本也无法识别,可以直接进到下一步

如果输出呈下列格式,则到此步无误

pub   rsa4096 2017-02-22 [SCEA]  
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88  
uid           [ unknown] Docker Release (CE deb) <[email protected]>  
sub   rsa4096 2017-02-22 [S]

将 Docker 版本库添加到APT源:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

执行后显示:

Get:1 https://download.docker.com/linux/ubuntu focal InRelease [36.2 kB]                                
Hit:2 http://cn.archive.ubuntu.com/ubuntu focal InRelease                                               
Get:3 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [3056 B]
Hit:4 http://cn.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://cn.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:6 http://cn.archive.ubuntu.com/ubuntu focal-security InRelease
Fetched 39.2 kB in 2s (16.1 kB/s)
Reading package lists... Done
  1. 接下来,我们用新添加的 Docker 软件包来进行升级更新。

    sudo apt-get update	
  2. 安装最新版本的 Docker Engine-Community 和 containerd (如果按照特定版本请看下一步)

    sudo apt-get install docker-ce docker-ce-cli containerd.io
  3. 如果要安装特定版本再执行这一步

    1. 查看docker 版本
    apt-cache madison docker-ce
    
      docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu  xenial/stable amd64 Packages
      docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu  xenial/stable amd64 Packages
      docker-ce | 18.06.1~ce~3-0~ubuntu       | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu  xenial/stable amd64 Packages
      docker-ce | 18.06.0~ce~3-0~ubuntu       | https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu  xenial/stable amd64 Packages
      ...

    使用第二列中的版本字符串安装特定版本,例如 5:18.09.1~ 3-0 ~ ubuntu-xenial。

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

安装检查

  1. 检测docker是否安装成功

    输入sudo docker run hello-world显示下列输出则安装成功

    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    1b930d010525: Pull complete                                                                                                                                  Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
    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/

如果本文帮助到了你,帮我点个广告可以咩(o′┏▽┓`o)


文章作者: Anubis
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Anubis !
评论
  目录