如何在RHEL 7/CentOS 7上安装Docker

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

如何在RHEL 7上安装Docker?在RHEL 7上安装Docker CE吗?容器彻底改变了应用程序部署和微服务的大规模可扩展性。 Docker改变了游戏规则,简化了在容器中运行和管理应用程序的过程。本文将指导我们完成在RHEL 7上安装Docker的过程。

对于CentOS 7,请在CentOS 7上检查Docker安装

注册RHEL 7服务器

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

sudo subscription-manager register --auto-attach

出现提示时输入用户名和密码。

启用所需的存储库

注册系统后,启用具有Docker软件包和依赖项的RHEL 7存储库。

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

在RHEL 7 Server /台式机上安装Docker

现在,我们可以通过运行以下命令在RHEL 7上安装Docker。

sudo yum install -y docker device-mapper-libs device-mapper-event-libs
sudo systemctl enable --now docker.service

确认服务状态。

$systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-07-14 17:10:51 EDT; 22h ago
     Docs: http://docs.docker.com
  Process: 10603 ExecReload=/bin/kill -s HUP $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 11056 (dockerd-current)
    Tasks: 46
   Memory: 156.8M
   CGroup: /system.slice/docker.service
.......

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

如果我们具有未使用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

测试Docker安装。

# docker pull hello-world
Using default tag: latest
Trying to pull repository registry.access.redhat.com/hello-world ... 
Pulling repository registry.access.redhat.com/hello-world
Trying to pull repository docker.io/library/hello-world ... 
latest: Pulling from docker.io/library/hello-world
1b930d010525: Pull complete 
Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f
Status: Downloaded newer image for docker.io/hello-world:latest

# docker run --rm 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/

现在,我们已经在RHEL 7系统上安装了Docker。