当前位置: 首页 > news >正文

Linux-Centos7安装Docker

文章目录

  • 一、前言
  • 二、Docker安装
    • 1、Docker及系统版本
    • 2、Docker的自动化安装
    • 3、Docker手动安装
      • 3.1、卸载Docker(可选)
      • 3.2、设置源仓库
      • 3.3、Docker安装
      • 3.4、Docker启动
      • 3.5、验证是否安装成功
        • 3.5.1、拉取镜像
        • 3.5.2、查看镜像
        • 3.5.3、运行镜像
      • 3.6、删除Docker

一、前言

本文将详细介绍Linux系统下如何安装Docker

二、Docker安装

1、Docker及系统版本

官网奉上:https://www.docker.com/
Docker从17.03版本之后分为CE(Community Edition: 社区版)和EE(Enterprise Edition: 企业版)。相对于社区版本,企业版本强调安全性,但需付费使用。这里我们使用社区版本即可。
Docker支持64位版本的CentOS 7和CentOS 8及更高版本,它要求Linux内核版本不低于3.10。
查看Linux版本的命令这里推荐两种:lsb_release -acat /etc/redhat-release
lsb_release -a查看效果:

[ ~]$ lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.6.1810 (Core)
Release: 7.6.1810
Codename: Core

cat /etc/redhat-release查看版本效果:

[~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

显然,当前Linux系统为CentOS7。再查一下内核版本是否不低于3.10。
查看内核版本有三种方式:
● cat /proc/version
● uname -a
● uname -r
三种形式都可以查看到内容版本,比如:

[ ~]$ uname -r
3.10.0-1160.45.1.el7.x86_64

可以看到,当前Linux内核版本满足Docker的需要。

2、Docker的自动化安装

Docker官方和国内daocloud都提供了一键安装的脚本,使得Docker的安装更加便捷。
官方的一键安装方式:
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
国内 daocloud一键安装命令:
curl -sSL https://get.daocloud.io/docker | sh
执行上述任一条命令,耐心等待即可完成Docker的安装。

3、Docker手动安装

手动安装Docker分三步:卸载、设置仓库、安装。

3.1、卸载Docker(可选)

第一步,卸载历史版本。这一步是可选的,如果之前安装过旧版本的Docker,可以使用如下命令进行卸载:

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

3.2、设置源仓库

第二步,设置仓库。新主机上首次安装Docker Engine-Community之前,需要设置Docker仓库。此后可从仓库安装和更新Docker。
在设置仓库之前,需先按照所需的软件包。yum-utils提供了yum-config-manager,并且device mapper存储驱动程序需要device-mapper-persistent-data和lvm2。

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

执行上述命令,安装完毕即可进行仓库的设置。使用官方源地址设置命令如下:

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

通常,官方的源地址比较慢,可将上述的源地址替换为国内比较快的地址:
● 阿里云:http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
● 清华大学源:https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

仓库设置完毕,即可进行Docker的安装。

3.3、Docker安装

执行一下命令,安装最新版本的 Docker Engine-Community 和 containerd。
sudo yum install -y docker-ce docker-ce-cli containerd.io
docker-ce为社区免费版本。稍等片刻,docker即可安装成功。但安装完成之后的默认是未启动的,需要进行启动操作。
如果不需要docker-ce-cli或containerd.io可直接执行如下命令:
yum install -y docker-ce
至此,完成Docker安装。

3.4、Docker启动

启动Docker的命令:

sudo systemctl start docker

3.5、验证是否安装成功

通过运行hello-world镜像来验证是否正确安装了Docker Engine-Community。

3.5.1、拉取镜像

sudo docker pull hello-world

在这里插入图片描述

3.5.2、查看镜像

sudo docker images
在这里插入图片描述

3.5.3、运行镜像

如果执行之后,控制台显示如下信息,则说明Docker安装和启动成功:

[root@hecs-360704 ~]# docker run hello-worldHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare 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/
……

在这里插入图片描述

除了启动Docker,一些其他启动相关的命令:
● 守护进程重启:systemctl daemon-reload
● 重启Docker服务:systemctl restart docker / service docker restart
● 关闭Docker服务:docker service docker stop / docker systemctl stop docker

3.6、删除Docker

删除安装包:

yum remove docker-ce

删除镜像、容器、配置文件等内容:
rm -rf /var/lib/docker

http://www.lryc.cn/news/161062.html

相关文章:

  • 前端Vue入门-day06-路由进阶
  • 数据库服务器是什么意思?数据库服务器有哪些?
  • 配电网智能软开关(sop)规划模型matlab
  • Qt 常用函数
  • UMA 2 - Unity Multipurpose Avatar☀️六.Advanced Occlusion高级遮挡功能解决皮肤服饰穿模
  • 深度解析自然语言处理之篇章分析
  • Python3.11教程3:模块和包(pip/conda)、文件系统(os/ shutil/json/pickle/openpyxl/xlrd)
  • shell 脚本工具(三剑客)
  • 基于微信小程序的智能垃圾分类回收系统,附源码、教程
  • 【C++进阶】:AVL树(平衡因子)
  • Python教程33:关于在使用zipfile模块,出现中文乱码的解决办法
  • 【疑难杂症】使用xshell连接云服务器连接不上
  • Qt MinGW / MSVC
  • 【数学建模】数据预处理
  • VMware 安装 黑群晖7.1.1-42962 DS918+
  • OpenCV(二十九):图像腐蚀
  • 【网络知识点】三次握手和四次挥手
  • CSS整理
  • OpenCV 06(图像的基本变换)
  • Java 中的日期时间总结
  • 创建10个线程并发执行(STL/Windows/Linux)
  • 三、创建各个展示模块组件
  • 推荐一款程序员截图神器!
  • 无涯教程-JavaScript - IMCSC函数
  • Ubuntu22.04 LTS 显卡相关命令
  • 《TCP/IP网络编程》阅读笔记--基于 TCP 的半关闭
  • Rust的模块化
  • vmware设置桥接模式后ip设置
  • 算法通关村第十七关:白银挑战-贪心高频问题
  • 目标检测评估指标mAP:从Precision,Recall,到AP50-95