AlmaLinux 8上安装Docker

查看本机Linux发行版本

[root@Alma_1 ~]# cat /etc/redhat-release 
AlmaLinux release 8.4 (Electric Cheetah)

第 1 步:更新 AlmaLinux / Rocky Linux 8 系统

通过将 AlmaLinux / Rocky Linux 8 系统操作系统包更新到最新版本来开始安装。

sudo dnf -y update

如果您有内核相关的更新,建议执行系统重启:

sudo reboot

第 2 步:添加 Docker CE 存储库

有一个开放的 Docker CE 存储库,其中包含用于基于 Red Hat 的 Linux 系统的 rpm 包。在 Rocky Linux 8 / AlmaLinux OS 8 上安装 Docker CE 之前,我们将添加此存储库。

安装提供yum-config-manager命令行工具的yum-utils 。

sudo dnf install -y yum-utils

安装该工具后,运行以下命令将 Docker CE 存储库添加到您的 AlmaLinux / Rocky Linux 8 系统:

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

感觉不安装yum也行,可以直接用dnf添加 Docker CE 存储库:

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

确认存储库可供使用:

sudo dnf repolist

如下:

repo id                                    repo name
appstream                                  AlmaLinux 8 - AppStream
baseos                                     AlmaLinux 8 - BaseOS
docker-ce-stable                           Docker CE Stable - x86_64
extras                                     AlmaLinux 8 - Extras

第3步:移除podman(也可以一开始就先删掉)

sudo dnf remove podman buildah

第4步:在 Rocky Linux 8 / AlmaLinux 8 上安装 Docker CE

现在 Docker 存储库已添加到我们的系统中,我们可以继续在 AlmaLinux 8 / Rocky Linux 8 上安装 Docker CE:

sudo dnf -y install docker-ce docker-ce-cli containerd.io

上面的命令将安装最新版本的 Docker Engine 和containerd。

Last metadata expiration check: 0:01:24 ago on Sat 21 Aug 2021 04:51:18 AM UTC.
Dependencies resolved.
===============================================================================================
 Package                Arch   Version                                  Repository        Size
===============================================================================================
Installing:
 containerd.io          x86_64 1.4.9-3.1.el8                            docker-ce-stable  30 M
 docker-ce              x86_64 3:20.10.8-3.el8                          docker-ce-stable  22 M
 docker-ce-cli          x86_64 1:20.10.8-3.el8                          docker-ce-stable  29 M
Installing dependencies:
 container-selinux      noarch 2:2.164.1-1.module_el8.4.0+2518+22932769 appstream         51 k
 docker-ce-rootless-extras
                        x86_64 20.10.8-3.el8                            docker-ce-stable 4.6 M
 docker-scan-plugin     x86_64 0.8.0-3.el8                              docker-ce-stable 4.2 M
 fuse-common            x86_64 3.2.1-12.el8                             baseos            21 k
 fuse-overlayfs         x86_64 1.6-1.module_el8.4.0+2518+22932769       appstream         72 k
 fuse3                  x86_64 3.2.1-12.el8                             baseos            50 k
 fuse3-libs             x86_64 3.2.1-12.el8                             baseos            94 k
 libcgroup              x86_64 0.41-19.el8                              baseos            69 k
 libslirp               x86_64 4.3.1-1.module_el8.4.0+2518+22932769     appstream         68 k
 slirp4netns            x86_64 1.1.8-1.module_el8.4.0+2518+22932769     appstream         50 k

Transaction Summary
===============================================================================================
Install  13 Packages

Total download size: 90 M
Installed size: 377 M

等待安装命令完成,然后启动服务:

[root@Alma_1 ~]# systemctl enable --now docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

检查服务状态:

[root@Alma_1 ~]# 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 Sat 2021-08-21 05:03:40 UTC; 1min 6s ago
     Docs: https://docs.docker.com
 Main PID: 63729 (dockerd)
    Tasks: 7
   Memory: 31.3M
   CGroup: /system.slice/docker.service
           └─63729 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Aug 21 05:03:39 Alma_1 dockerd[63729]: time="2021-08-21T05:03:39.358666548Z" level=warning msg>
Aug 21 05:03:39 Alma_1 dockerd[63729]: time="2021-08-21T05:03:39.358915918Z" level=warning msg>
Aug 21 05:03:39 Alma_1 dockerd[63729]: time="2021-08-21T05:03:39.359063253Z" level=info msg="L>
Aug 21 05:03:39 Alma_1 dockerd[63729]: time="2021-08-21T05:03:39.806752974Z" level=info msg="D>
Aug 21 05:03:39 Alma_1 dockerd[63729]: time="2021-08-21T05:03:39.933976969Z" level=info msg="F>
Aug 21 05:03:40 Alma_1 dockerd[63729]: time="2021-08-21T05:03:40.037928534Z" level=info msg="L>
Aug 21 05:03:40 Alma_1 dockerd[63729]: time="2021-08-21T05:03:40.054260442Z" level=info msg="D>
Aug 21 05:03:40 Alma_1 dockerd[63729]: time="2021-08-21T05:03:40.054374465Z" level=info msg="D>
Aug 21 05:03:40 Alma_1 systemd[1]: Started Docker Application Container Engine.
Aug 21 05:03:40 Alma_1 dockerd[63729]: time="2021-08-21T05:03:40.080113818Z" level=info msg="A>
lines 1-20/20 (END)

将您的用户添加到 docker 组(因我目前是root用户登录,故无需添加)

sudo usermod -aG docker $USER
newgrp docker

确认您是否能够在没有 sudo 的情况下运行任何 docker 命令(非root用户验证此项):

$ docker --version
Docker version 20.10.8, build 3967b7d

第 5 步:运行 docker 容器

让我们通过拉取 alpine linux 和hello-world镜像来测试我们在 AlmaLinux 8 / Rocky Linux 8 上的 Docker CE 安装:

docker pull alpine:latest
[root@Alma_1 ~]# docker pull alpine:latest
latest: Pulling from library/alpine
29291e31a76a: Pull complete 
Digest: sha256:eb3e4e175ba6d212ba1d6e04fc0782916c08e1c9d7b45892e9796141b1d379ae
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
docker pull alpine:latest
[root@Alma_1 ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

从 alpine 镜像运行一个 docker 容器:

docker run hello-world
[root@Alma_1 ~]# 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/

我们可以确认我们在 AlmaLinux OS 8 / Rocky Linux 8 上的 Docker 安装工作正常。您现在可以使用 Docker 和有用的工具(例如 Docker Compose)构建容器化应用程序。并最终将它们迁移到 Kubernetes 环境。


参考:

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值