3、CentOS7 上安装 Docker

本文介绍了在CentOS系统中通过仓库安装Docker的详细过程,包括安装yum-utils,设置阿里云镜像仓库,安装Docker引擎,启动和测试Docker服务,以及如何卸载Docker并清理本地数据。
摘要由CSDN通过智能技术生成

目录

官方文档

Installation methods

Install using the repository

1、安装 yum-utils 软件包

 2、设置仓库

 3、安装 Docker 引擎

 4、启动 Docker 服务

5、测试

6、卸载 Docker

 停掉我们 Docker 后台服务

 卸载

删除本地数据


官方文档

Install Docker Engine on CentOS | Docker Documentation

Installation methods

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

  • You can set up Docker’s repositories and install from them, for ease of installation and upgrade tasks. This is the recommended approach.

  • You can 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, you can use automated convenience scripts to install Docker.

 Docker 官方提供了三种方式,分别是仓库安装、RPM包安装和 scripts 脚本安装。

官方推荐用 仓库安装。

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.

在你开始第一次为一台新的主机安装 Docker 引擎之前,你需要设置 Docker 仓库。从那以后,你可以从仓库安装和更新 Docker。

Set up the repository

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

1、安装 yum-utils 软件包

sudo yum install -y yum-utils

 提示 完毕!就说明已经安装完成

 2、设置仓库

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

因为 https://download.docker.com 是国外的网站,所以经常会连不上

 所以我们使用国内阿里云的镜像仓库

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

 3、安装 Docker 引擎

sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

 会有两次选择,全部选y就可以

 

 

 完毕!

 4、启动 Docker 服务

sudo systemctl start docker

5、测试

 测试1:看看 docker 版本

docker version

 测试2:运行 ​hello-world 镜像

sudo docker run hello-world

 执行 docker run  image_name

如果本地有镜像,直接生成容器实例;如果本地没有镜像,从远程仓库拉取镜像,然后生成容器实例。输出【Hello from Docker! This message shows that ... correctly】这段提示以后,hello world就会停止运行,容器自动终止。

 

6、卸载 Docker

 停掉我们 Docker 后台服务

systemctl stop docker 

 卸载

sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras

删除本地数据

sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值