根据官网在Centos下安装docker环境

Prerequisites(先决条件)

OS requirements

To install Docker Engine, you need a maintained version of CentOS 7 or 8. Archived versions aren’t supported or tested.
The centos-extras repository must be enabled. This repository is enabled by default, but if you have disabled it, you need to re-enable it.

就是说需要 CentOS 7或8 ,早期版本不支持这种容器基础。必须启用centos-extras存储库。 该存储库默认情况下处于启用状态,但是如果已禁用它,则需要重新启用它
检测机器版本命令,内核版本最后在3.8以上:

uname -a
# Linux centos-local-7 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/redhat-release
# CentOS Linux release 7.8.2003 (Core)
# cat /proc/version 也可以

Uninstall old versions

Older versions of Docker were called docker or docker-engine. If these are installed, uninstall them, along with associated dependencies.

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

这是由于国内访问不到docker官方镜像的缘故
可以通过aliyun的源来完成:

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Installation methods(三种安装方法)

You can install Docker Engine in different ways, depending on your needs:

  • Most users set up Docker’s repositories and install from them, for ease of installation and upgrade tasks. This is the recommended approach.
  • Some users download the RPM package and install it manually and manage upgrades completely manually. This is useful in situations such as installing Docker on air-gapped systems with no access to the internet.
  • In testing and development environments, some users choose to use automated convenience scripts to install Docker.

Install using the repository

Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.

Set up the repository

Install the yum-utils package (which provides the yum-config-manager utility) and set up the stable repository.

 sudo yum install -y yum-utils \
    device-mapper-persistent-data \
    lvm2
 # 这里主要是 yum-utils 为了后面用 yum-config-manager 添加一个docker-ce的yum源

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

上面的是官方贴出的源,国内访问不到,给成使用国内镜像(阿里云的docker-ce源)

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

可以选择是否开启edge和test仓库,这里调过操作:
命令:sudo yum-config-manager --enable docker-ce-nightly
命令:sudo yum-config-manager --enable docker-ce-test
命令:sudo yum-config-manager --disable docker-ce-test

Install Docker Engine

查看docker源上现有的所有版本:

yum list docker-ce --show-duplicates

安装docker-ce,不带版本号则下载最新的

sudo yum install docker-ce
# 如果指定版本:sudo yum install docker-ce-[version]

官网给的安装命令是:sudo yum install docker-ce docker-ce-cli containerd.io 由于阿里云的docker-ce源已经做好了相关的依赖,只用 sudo yum install docker-ce 命令就可以全部安装。

启动docler服务

# 开启开机自启动
# sudo systemctl enable docker

# 开启docker服务
sudo systemctl start docker

查看版本

docker version

没有启动docker时,只会显示Client的版本信息
在这里插入图片描述
启动服务后查看版本会多一条Server信息:
在这里插入图片描述
查看docker信息:

docker info

Verify that Docker Engine is installed correctly by running the hello-world image.

sudo docker run hello-world

在这里插入图片描述
To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.

    docker客户端连接到Docker守护进程(也就是服务端)。这说明docker本质上是一个C/S架构的程序。

  2. The Docker daemon pulled the “hello-world” image from the Docker Hub.
    (amd64)

    docker守护进程从Docker Hub(官方的镜像仓库,可以类别GitHub) 上拉取“hello-world”镜像(本地没有所有去远程拉取)。

  3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.

    docker服务端根据刚才拉取的镜像创建了一个新的容器,这个容器工作产生了我们看到的这些信息

  4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

    docker服务通过流的方式将容器运行产生的结果输出到客户端,也就是发送到了我们的终端。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值