• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
gys001
博客园    首页    新随笔    联系   管理    订阅  订阅

centos7安装docker(联网)

环境准备

目前,CentOS 仅发行版本中的内核支持 Docker。Docker 运行在CentOS 7 (64-bit)上,要求系统为64位、Linux系统内核版本为 3.8以上,这里选用Centos7.9

查看自己的版本及内核
[root@docker ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@docker ~]# uname -r
3.10.0-1160.el7.x86_64
禁用firewalld、selinux
[root@docker ~]# systemctl stop firewalld
[root@docker ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@docker ~]# setenforce 0
[root@docker ~]# sed -i 's/SELINUX=enforcing/\SELINUX=disabled/' /etc/selinux/config

安装docker 

下载阿里docker镜像源
[root@docker ~]# curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo  
生成缓存
[root@docker ~]# yum makecache
安装最新版本
[root@docker ~]# yum -y install docker-ce docker-ce-cli containerd.io
设置开机自启并启动
[root@docker ~]# systemctl enable docker --now  
也可直接按照官网步骤安装docker,这里就不演示了,附上官网安装地址
https://docs.docker.com/engine/install/centos/

查看docker版本,有如下显示即表示安装成功

[root@docker ~]# docker version

 配置阿里云加速

每个阿里云账号提供一个唯一的加速地址。

登录阿里云,进入 工作台 -> 容器镜像服务 -> 镜像工具 -> 镜像加速器。

直接复制命令运行即可,这里我自己的镜像地址省略

 

mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxxxxxxx.mirror.aliyuncs.com"]  
}
EOF

刷新配置、重启docker

systemctl daemon-reload

systemctl restart docker

 

运行hello-world测试

[root@docker ~]# docker run hello-world
会有warning
WARNING: IPv4 forwarding is disabled. Networking will not work.
原因:未开启路由转发功能

 

开启路由转发功能


[root@docker ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1                       #添加这一行,开启路由转发功能
[root@docker ~]# sysctl -p                    #刷新配置

再次运行hello-world测试,无warning
[root@docker ~]# docker run hello-world

 

参考

尚硅谷2022版Docker实战教程  https://www.bilibili.com/video/BV1gr4y1U7CY

https://www.yuque.com/tmfl/cloud/ay9g1r
https://www.yuque.com/fairy-era/yg511q/lb7t23

 

posted @ 2022-10-19 18:45  gys001  阅读(179)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3