Docker之路-版本选择及安装

系统要求


docker版本介绍

docker官方提供2个版本,一个是docker企业版docker-EE,另外一个则是社区版docker-ce,我们在学习或者测试环境使用docker-ce版本即可。

操作系统版本要求

要想在centos上安装并运行docker,那么你需要centos-7及以上的版本,旧于这个版本的系统将不支持。

其次,你必须启用centos-extras存储库。默认情况下是开启的,但如果您禁用了它,则需要重新启用它。

建议使用overlay2存储驱动程序。

卸载旧的docker版本

老版本的docker也被叫做:docker或docker-engine。 如果你安装这些版本,那么请卸载它,以及它的依赖项目:

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

如果yum反馈这些包都没有安装,也没有关系,忽略它;

安装docker-ce


docker的安装完成后,所有的内容都保存在/var/lib/docker目录下,保存了和docker相关的images, containers, volumes, networks等信息,Docker Engine - Community 的包叫做docker-ce

安装docker-ce有很多种方法:

  1. 选择使用docker的repositories来安装docker,这样可以简化安装和升级任务。比较推荐,这是大多人的选择
  2. PRM包安装,下载RPM包手动安装,并完全手动管理升级。在no access to the internet的环境下是不错的选择
  3. 自动化脚本,通常在测试环境和开发环境,会选择使用自动化的脚本来安装docker

设置yum仓库

要使用docker的repo来安装docker,我们首先需要安装yum-utils,device-mapper-persistent-data,lvm2。其中yum-utils 提供了 yum-config-manager 功能,后2者用于服务设备映射存储驱动程序。

$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

添加yum仓库

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

启动docker-nightly版本,docker-ce提供了3种方式用于docker的更新,稳定,测试和夜间(官网原文):

  • Stable gives you latest releases for general availability.
  • Test gives pre-releases that are ready for testing before general availability.
  • Nightly gives you latest builds of work in progress for the next major release.
# 启动nightly更新方式
$ sudo yum-config-manager --enable docker-ce-nightly

# 禁用
$ sudo yum-config-manager --disable docker-ce-nightly

安装docker


安装最新版本:

$ sudo yum install docker-ce docker-ce-cli containerd.io

如果你不想安装最新版本,那么可以查看仓库中包含哪些版本,选择特定的版本进行安装:

$ yum list docker-ce --showduplicates | sort -r
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, priorities
Installed Packages
docker-ce.x86_64    3:19.03.2-3.el7                            docker-ce-stable
docker-ce.x86_64    3:19.03.2-3.el7                            @docker-ce-stable
docker-ce.x86_64    3:19.03.1-3.el7                            docker-ce-stable
docker-ce.x86_64    3:19.03.0-3.el7                            docker-ce-stable
docker-ce.x86_64    3:18.09.9-3.el7                            docker-ce-stable
...

# 选择特定版本安装
$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

启动docker服务

$ systectm star docker

验证docker服务是否安装成功,运行系统提供的一个镜像,输出Hello from 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:b8ba256769a0ac28dd126d584e0a2011cd2877f3f76e093a7ae560f2a5301c00
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/

卸载docker


有可能有一天你不想再运行docker服务了,或者该主机有别的用途,不想docker占用主机资源,那么你可以卸载docker服务。

# stop docker
$ systemctl stop docker

# Uninstall the Docker package
$ systemctl remove docker

# 删除主机上的映像、容器、卷或自定义配置文件
$ sudo rm -rf /var/lib/docker

猜你喜欢

转载自www.cnblogs.com/vinsent/p/11613586.html