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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了