在RHEL 7 Linux上安装Docker CE

时间:2020-02-23 14:31:41  来源:igfitidea点击:

此处共享的步骤用于在RHEL 7 Linux上安装Docker CE。 Docker是主要的主要容器运行时引擎,用于开发和运行生产中的微服务应用程序。可以在RHEL 7 Desktop/Linux计算机上安装两种版本的Docker:Docker社区版(Docker CE)Docker企业版(Docker EE)

本教程适用于在RHEL 7上安装Docker Community Edition。如果我们对Docker Enterprise Edition感兴趣,请检查其功能以及与Community Edition的主要区别。

因此,让我们在RHEL 7 Linux系统上安装Docker CE。

注册RHEL 7服务器

首先向Red Hat Subscription Management或者Satellite服务器注册RHEL 7服务器。

sudo subscription-manager register --auto-attach

系统将提示我们提供Red Hat门户用户名和密码。

启用所需的存储库

我们需要启用以下存储库才能在RHEL 7上安装Docker Community Edition。它们包含许多运行Docker所需的依赖项。

sudo subscription-manager repos --enable=rhel-7-server-rpms \
  --enable=rhel-7-server-extras-rpms \
  --enable=rhel-7-server-optional-rpms

在RHEL 7 Linux上安装Docker CE

在添加Docker CE Yum存储库之前安装必需的软件包。

sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

将稳定的Docker CE存储库添加到RHEL 7系统。

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

最后,在RHEL 7上安装最新版本的Docker CE,并附带最新的容器。

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

如果要查看所有可用的Docker版本,请使用:

$sudo yum list docker-ce --showduplicates | sort -r

启动并启用Docker服务

现在启动并启用Docker服务以在启动时启动。

sudo systemctl enable --now docker.service

检查docker版本:

$docker version
Client: Docker Engine - Community
 Version:           19.03.7
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        7141c199a2
 Built:             Wed Mar  4 01:24:10 2017
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.7
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       7141c199a2
  Built:            Wed Mar  4 01:22:45 2017
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

设置不安全的注册表/阻止注册表

如果我们具有未使用SSL加密的本地Docker注册表进行访问,则可能需要将它们列入白名单。

$sudo vim /etc/containers/registries.conf
.....
[registries.insecure]
registries = ["reg1.example.com","reg2.example.com"]

要阻止访问注册表,请在registries.block部分下添加注册表URL。

[registries.block]
registries = ['reg10.example.com']

如果对配置文件进行更改,请重新启动docker服务。

sudo systemctl restart docker

在RHEL 7上测试Docker安装。

$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/