玖叶教程网

前端编程开发入门

Docker教程第五章:安装-Docker引擎版本(ubuntu)

准备

环境要求,需要一个64bit 的ubuntu系统,Docker Engine支持x86_64(或amd64)、armhf、arm64和s390x架构, 引擎支持overlay2, aufs and btrfs存储驱动,且docker引擎默认支持overlay2。支持ubuntu 版本如下:

  • Ubuntu Impish 21.10
  • Ubuntu Hirsute 21.04
  • Ubuntu Focal 20.04 (LTS)
  • Ubuntu Bionic 18.04 (LTS)

执行如下命令卸载老版本docker引擎,/var/lib/docker/下存储了老的镜像、挂载卷、容器等文件如果不需要建议删除

sudo apt-get remove docker docker-engine docker.io containerd runc

安装方式一共三种:

  • 仓库方式安装
  • 安装包方式安装
  • 脚本安装


采用仓库安装

安装工具

$ sudo apt-get update
$ sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

添加GPG秘钥

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gp

配置仓库源

 $ echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

安装引擎

查看指定版本

apt-cache madison docker-ce

最新版本安装

 $ sudo apt-get update
 $ sudo apt-get install docker-ce docker-ce-cli containerd.io

基于版本安装

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

验证安装

使用docker 运行hello-world镜像

banbohub@banbohub .~ $ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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/

更新镜像

运行sudo apt-get update 根据相应说明进行升级,或者卸载后重新安装部署

采用安装包

如果无法使用ubuntu repository 进行安装,可以采用下载安装包(.deb)的形式进行安装

下载安装包

根据ubuntu版本,以及处理器架构(amd64, armhf, arm64, 活着 s390x)在https://download.docker.com/linux/ubuntu/dists/选择相应的docker 引擎版本下载

安装引擎

 sudo dpkg -i /path/to/package.deb

验证安装

使用docker 运行hello-world镜像

banbohub@banbohub .~ $ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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/D: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/

更新镜像

需要重新下载新版本的安装包卸载,老版本后重新安装

脚本安装

Docker 官方为了简化安装流程,提供了一套安装脚本,Ubuntu 和 Debian 系统可 以使用这套脚本安装,但是不建议将便利脚本用于生产环境。该脚本的源代码是开源的,可以在GitHub上的docker安装存储库中找到。

$ curl -fsSL https://get.docker.com -o get-docker.sh 
$ sh ./get-docker.sh

省略sudo

创建 docker 用户组

sudo groupadd docker

将用户添加到 docker 组

sudo usermod -aG docker {your_username}

相关推荐

Docker教程第四章:Docker概念

Docker教程第三章:Docker架构

Docker教程第二章:Docker生态


Docker教程第一章:Docker介绍

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言