Docker构建微服务框架(二):Docker的安装和部署

Docker1.png

在Ubuntu中安装Docker

要安装Docker Engine,您需要以下Ubuntu版本之一的64位版本:

  • Ubuntu Eoan 19.10
  • Ubuntu Bionic 18.04(LTS)
  • Ubuntu Xenial 16.04(LTS)
  • 其他最新版本

安装前的检查

  1. 检查内核版本
    Docker需要3.10+内核的linux操作系统。
$ uname -a
Linux ubuntu 5.4.0-26-generic #30-Ubuntu SMP Mon Apr 20 16:58:30 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  1. 检查Device Mapper
$ ls -l /sys/class/misc/device-mapper
lrwxrwxrwx 1 root root 0 May 24 08:45 /sys/class/misc/device-mapper -> ../../devices/virtual/misc/device-mapper

卸载旧的版本

  1. 较旧的Docker版本名称为docker,docker.io或docker-engine。 如果已安装,请卸载它们:
$ sudo apt-get remove docker docker-engine docker.io containerd runc

如果提示以下结果,说明系统中没有安装较久版本的Docker。

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package docker-engine

设置存储库

  1. 更新apt软件包索引并安装软件包以允许apt通过HTTPS使用存储库:
$ sudo apt-get update

$ sudo apt-get install 
    apt-transport-https 
    ca-certificates 
    curl 
    gnupg-agent 
    software-properties-common
  1. 添加Docker的官方GPG密钥:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK

通过搜索指纹的后8个字符,验证您现在是否拥有带有指纹的密钥 。

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) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]
  1. 使用以下命令来设置稳定的存储库。
$ sudo add-apt-repository 
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu 
   $(lsb_release -cs) 
   stable"

安装Docker

  1. 更新apt包索引,并安装最新版本的Docker Engine和容器。
 $ sudo apt-get update
 $ sudo apt-get install docker-ce docker-ce-cli containerd.io
  1. 通过运行hello-world 映像来验证是否正确安装了Docker Engine 。
$ 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.

终端出现Hello from Docker!提示,说明Docker已经成功的安装到您的系统中。

原文地址:https://www.cnblogs.com/kylebao/p/13048800.html