centos下的docker引擎安装

本文详细介绍了在64位操作系统上安装和配置Docker的步骤,包括环境准备、关闭防火墙、配置yum源、安装及启动Docker、配置私有仓库、添加加速器等,最后通过运行hello-world镜像验证Docker引擎是否安装成功。

基础环境:

水平有限,仅供参考
64位操作系统
内核不低于3.10
内核必须支持任何一种存储驱动:如 device-mapper
通过 uname -a 查看内核版本和64位CPU
通过ls -l /sys/class/misc/device-mapper查看是否有

在这里插入图片描述

关闭防火墙一系列东西

1.关闭防火墙:systemctl stop firewalld
2.防火墙开机不自启:systemctl disable firewalld
3.这个必须要:setenforce 0
4.还有这几个:

iptables -F
iptables -X
iptables -Z

在这里插入图片描述

配置yum源

新建yum源文件,原来的yum不用移走

[centos7]
name=centos7
baseurl=file:///opt/centos7
enbald=1
gpgcheck=0

然后更新yum

  yum update -y

在这里插入图片描述

开启路由转发

添加如下三行
然 sysctl -p 生效配置

[root@cuihaiqiao ~]#vi  /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0

[root@cuihaiqiao ~]#sysctl -p   ##生效配置

在这里插入图片描述

安装docker

yum install docker-io -y

安装完后启动: systemctl restart docker (启动不了重启虚拟机)
加入开机启动: systemctl enable docker
检查docker运行状态:systemctl status dockerps -aux | grep docker

查看版本信息:docker --version

在这里插入图片描述

添加仓库地址

配置私有仓库(根据自己的ip修改ip)

[root@cuihaiqiao ~]#vi /etc/sysconfig/docker
ADD_REGISTRY='--add-registry 192.168.100.10:5000'
INSECURE_REGISTRY='--insecure-registry 192.168.200.143:5000'

在这里插入图片描述

添加加速器

我这里是阿里云加速器
网上还有很多其他的

[root@cuihaiqiao ~]# vi /etc/docker/daemon.json

{
  "registry-mirrors": ["https://97by74eg.mirror.aliyuncs.com"]
}

在这里插入图片描述
生效加速器:systemctl daemon-reload
然后重启:systemctl restart docker
在这里插入图片描述

验证docker是否可以运行

[root@cuihaiqiao ~]# docker run hello-world

看到对应输出结果

[root@cuihaiqiao ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
Trying to pull repository 192.168.100.10:5000/hello-world ... 
Trying to pull repository docker.io/library/hello-world ... 
latest: Pulling from docker.io/library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:8e3114318a995a1ee497790535e7b88365222a21771ae7e53687ad76563e8e76
Status: Downloaded newer image for docker.io/hello-world:latest

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/

至此docker引擎安装完成

### 如何在CentOS安装Docker引擎 #### 卸载旧版本 为了确保系统的兼容性和稳定性,在安装新的 Docker 版本之前,建议先卸载任何已有的旧版 Docker 软件包。可以执行如下命令来移除旧版本: ```bash sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine ``` #### 设置存储库 更新软件源以获取最新的 Docker CE (社区版) 和 EE (企业版),这一步骤对于获得稳定的新版本至关重要。 ```bash # 安装必要的依赖项以便能够使用 HTTPS 方法访问仓库并管理 GPG 密钥 sudo yum install -y yum-utils # 添加官方的 Docker APT 仓库 sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo ``` #### 安装最新版本的 Docker 引擎 通过 YUM 包管理工具直接安装经过验证过的 Docker 社区版及其 CLI 工具以及 Containerd 组件。 ```bash sudo yum -y install docker-ce docker-ce-cli containerd.io ``` 完成上述操作之后,可以通过 `docker -v` 命令确认当前安装的是哪个版本[^3]。 #### 启动 Docker 服务 为了让 Docker 可用,还需要启动其守护进程,并将其设置为开机自启。 ```bash sudo systemctl start docker sudo systemctl enable docker ``` #### 测试安装是否成功 最后,运行一个简单的 Hello-world 镜像来检验 Docker 是否正常工作。 ```bash sudo docker run hello-world ``` 如果一切顺利的话,将会看到一条欢迎消息,表示 Docker 成功安装并且正在运行中。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值