在Ubuntu16.04下安装Docker

  • 确认系统信息
    -uname -r 查看内核版本信息
    cat /etc/os-release 查看发行版本的信息
    etc@etc-ruc:~$ uname -r
    4.15.0-122-generic
    etc@etc-ruc:~$ cat /etc/os-release 
    NAME="Ubuntu"
    VERSION="16.04.7 LTS (Xenial Xerus)"
    ID=ubuntu
    ID_LIKE=debian
    PRETTY_NAME="Ubuntu 16.04.7 LTS"
    VERSION_ID="16.04"
    HOME_URL="http://www.ubuntu.com/"
    SUPPORT_URL="http://help.ubuntu.com/"
    BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
    VERSION_CODENAME=xenial
    UBUNTU_CODENAME=xenial
    

安装Docker引擎的官方文档在:https://docs.docker.com/engine/install/ubuntu/

  • 卸载旧版的Docker

    etc@etc-ruc:~$ sudo apt-get remove docker docker-engine docker.io containerd runc
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Package 'docker-engine' is not installed, so not removed
    Package 'docker' is not installed, so not removed
    Package 'containerd' is not installed, so not removed
    Package 'docker.io' is not installed, so not removed
    Package 'runc' is not installed, so not removed
    The following packages were automatically installed and are no longer required:
      linux-headers-4.4.0-193 linux-headers-4.4.0-193-generic
      linux-image-4.15.0-120-generic linux-image-4.4.0-193-generic
      linux-modules-4.15.0-120-generic linux-modules-4.4.0-193-generic
      linux-modules-extra-4.15.0-120-generic linux-modules-extra-4.4.0-193-generic
    Use 'sudo apt autoremove' to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    
  • 安装一些依赖

    etc@etc-ruc:~$ sudo apt-get update
    Hit:1 http://mirrors.ustc.edu.cn/ubuntu xenial InRelease
    Hit:2 http://mirrors.ustc.edu.cn/ubuntu xenial-updates InRelease               
    Hit:3 http://mirrors.ustc.edu.cn/ubuntu xenial-backports InRelease             
    Hit:4 https://download.docker.com/linux/ubuntu xenial InRelease
    Hit:5 https://typora.io/linux ./ InRelease                    
    Hit:6 http://packages.ros.org/ros/ubuntu xenial InRelease   
    Reading package lists... Done      
    etc@etc-ruc:~$ sudo apt-get install \
    >     apt-transport-https \
    >     ca-certificates \
    >     curl \
    >     gnupg-agent \
    >     software-properties-common
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    apt-transport-https is already the newest version (1.2.32ubuntu0.1).
    ca-certificates is already the newest version (20201027ubuntu0.16.04.1).
    curl is already the newest version (7.47.0-1ubuntu2.16).
    gnupg-agent is already the newest version (2.1.11-6ubuntu2.1).
    software-properties-common is already the newest version (0.96.20.10).
    The following packages were automatically installed and are no longer required:
      linux-headers-4.4.0-193 linux-headers-4.4.0-193-generic
      linux-image-4.15.0-120-generic linux-image-4.4.0-193-generic
      linux-modules-4.15.0-120-generic linux-modules-4.4.0-193-generic
      linux-modules-extra-4.15.0-120-generic linux-modules-extra-4.4.0-193-generic
    Use 'sudo apt autoremove' to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    
  • 添加Docker的GPG密钥

    etc@etc-ruc:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    OK
    etc@etc-ruc:~$ sudo apt-key fingerprint 0EBFCD88
    pub   4096R/0EBFCD88 2017-02-22
          Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
    uid                  Docker Release (CE deb) <docker@docker.com>
    sub   4096R/F273FCD8 2017-02-22
    
    etc@etc-ruc:~$ sudo add-apt-repository \
    >    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    >    $(lsb_release -cs) \
    >    stable"
    
  • 安装Docker引擎

    etc@etc-ruc:~$ sudo apt-get update
    Hit:1 http://mirrors.ustc.edu.cn/ubuntu xenial InRelease
    Hit:2 http://mirrors.ustc.edu.cn/ubuntu xenial-updates InRelease               
    Hit:3 http://mirrors.ustc.edu.cn/ubuntu xenial-backports InRelease             
    Hit:4 https://download.docker.com/linux/ubuntu xenial InRelease                
    Hit:5 http://packages.ros.org/ros/ubuntu xenial InRelease
    Hit:6 https://typora.io/linux ./ InRelease         
    Reading package lists... Done
    etc@etc-ruc:~$  sudo apt-get install docker-ce docker-ce-cli containerd.io
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    containerd.io is already the newest version (1.3.7-1).
    docker-ce-cli is already the newest version (5:19.03.13~3-0~ubuntu-xenial).
    docker-ce is already the newest version (5:19.03.13~3-0~ubuntu-xenial).
    The following packages were automatically installed and are no longer required:
      linux-headers-4.4.0-193 linux-headers-4.4.0-193-generic
      linux-image-4.15.0-120-generic linux-image-4.4.0-193-generic
      linux-modules-4.15.0-120-generic linux-modules-4.4.0-193-generic
      linux-modules-extra-4.15.0-120-generic linux-modules-extra-4.4.0-193-generic
    Use 'sudo apt autoremove' to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    
  • 查看当前docker安装是否成功

    etc@etc-ruc:~$ docker version
    Client: Docker Engine - Community
     Version:           19.03.13
     API version:       1.40
     Go version:        go1.13.15
     Git commit:        4484c46d9d
     Built:             Wed Sep 16 17:02:59 2020
     OS/Arch:           linux/amd64
     Experimental:      false
    Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/version: dial unix /var/run/docker.sock: connect: permission denied
    
  • 出现一个权限错误,用户权限下使用Docker命令需要sudo,解决办法将当前用户添加到Docker用户组,添加成功后docker version正常显示其客户端和服务端的版本信息:

    etc@etc-ruc:~$ sudo gpasswd -a $USER docker
    Adding user etc to group docker
    etc@etc-ruc:~$ newgrp docker
    etc@etc-ruc:~$ docker version
    Client: Docker Engine - Community
     Version:           19.03.13
     API version:       1.40
     Go version:        go1.13.15
     Git commit:        4484c46d9d
     Built:             Wed Sep 16 17:02:59 2020
     OS/Arch:           linux/amd64
     Experimental:      false
    
    Server: Docker Engine - Community
     Engine:
      Version:          19.03.13
      API version:      1.40 (minimum version 1.12)
      Go version:       go1.13.15
      Git commit:       4484c46d9d
      Built:            Wed Sep 16 17:01:30 2020
      OS/Arch:          linux/amd64
      Experimental:     false
     containerd:
      Version:          1.3.7
      GitCommit:        8fba4e9a7d01810a393d5d25a3621dc101981175
     runc:
      Version:          1.0.0-rc10
      GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
     docker-init:
      Version:          0.18.0
      GitCommit:        fec3683
    
  • 实际上可以通过ps命令查看一下Docker,它是以Daemon(守护进程/服务)的形式在后台运行:

    etc@etc-ruc:~$ ps -axf|grep docker
    10381 pts/18   S+     0:00          |       \_ grep --color=auto docker
     1541 ?        Ssl    0:32 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
    
  • 测试一下hello wolrd镜像:

    etc@etc-ruc:~$ sudo docker run hello-world
    
    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/
    
  • 查看Docker的镜像仓库:

    etc@etc-ruc:~$ docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    hello-world         latest              bf756fb1ae65        10 months ago       13.3kB
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值