CentOS8安装docker

CentOS8 安装 Docker CE

警告:切勿在没有配置 Docker YUM 源的情况下直接使用 yum 命令安装 Docker.

准备工作

系统要求

Docker CE 支持 64 位版本 CentOS 7,并且要求内核版本不低于 3.10。 CentOS 7 满足最低内核的要求,但由于内核版本比较低,部分功能(如 overlay2 存储层驱动)无法使用,并且部分功能可能不太稳定。

卸载旧版本

旧版本的 Docker 称为 docker 或者 docker-engine,使用以下命令卸载旧版本:

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

使用 yum 安装

执行以下命令安装依赖包:

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

鉴于国内网络问题,强烈建议使用国内源,官方源请在注释中查看。

执行下面的命令添加 yum 软件源:

$ yum-config-manager --add-repo  https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo

$ sed -i 's/download.docker.com/mirrors.ustc.edu.cn\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo

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

如果需要测试版本的 Docker CE 请使用以下命令:

$ yum-config-manager --enable docker-ce-test

如果需要每日构建版本的 Docker CE 请使用以下命令:

$ yum-config-manager --enable docker-ce-nightly

安装 Docker CE

更新 yum 软件源缓存,并安装 docker-ce

# 更新yum软件缓存
$ yum makecache timer
# 安装 docker
$ yum -y install docker-ce

centos8安装docker-ce时出现requires containerd.io≥1.2.2-3

package docker-ce-3:19.03.12-3.el7.x86_64 requires [containerd.io](http://containerd.io/) >= 1.2.2-3, but none of the providers can be installed

需要先安装containerd

# 获取containerd
$ wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.1.el7.x86_64.rpm
# 安装docker所需containerd
$ yum -y install ./containerd.io-1.2.13-3.1.el7.x86_64.rpm
#继续安装docker
$ yum install docker-ce docker-ce-cli

启动 Docker

# 启动docker 
$ systemctl start docker
# 将docker服务加入开机自启
$ systemctl enable docker

测试安装

# 下载安装hello-word镜像
$ docker run hello-word

# 运行上述命令会得到以下结果,证实安装成功
#//未在本地发现hello-word镜像,未指定版本时,会使用latest作为版本号
#Unable to find image 'hello-world:latest' locally
#//拉取hello-word
#latest: Pulling from library/hello-world
#//拉取完成
#0e03bdcc26d7: Pull complete 
#Digest: sha256:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5
#Status: Downloaded newer image for hello-world:latest
#// hello-word镜像运行成功
#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/
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值