Linux上的Docker安装

 前提条件:docker建议安装在centos7平台上,且内核不低于3.10。    其他平台可能会有警告信息。

 1. 基础环境配置

 

wget -O /etc/yum.repos.d/Centos-base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yun.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum clean all
yum makecache

2. 开启linux内核的流量转发

cat <<EOF > /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.ip_forward=1
EOF

3. 要使上述配置文件生效,就需要加载修改内核参数的配置文件

 

[root@VM-4-9-centos ~]# sysctl -p /etc/sysctl.d/docker.conf

 

如果报错:No such file or directory

sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: No such file or directory
sysctl: cannot stat /proc/sys/net/bridge/beidge-nf-call-iptables: No such file or directory
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.ip_forward = 1

就执行如下命令:

[root@VM-4-9-centos ~]# modprobe br_netfilter

然后再重新执行:

 sysctl -p /etc/sysctl.d/docker.conf

4. 利用yum快速安装docker

复制代码
安装docker-ce社区版


# 查看源中可用版本

  yum list docker-ce --showduplicates | sort -r

 

  如果没有匹配项,则下载阿里源repo文件  第一个是阿里云自带仓库  第二个是阿里云提供的docker专属repo仓库

  curl -o /etc/yum.repos.d/CentOS-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

 # 更新yum缓存

yum clean all && yum makecache

# docker正式安装
复制代码
yum install docker-ce-20.10.6 -y

如果要安装旧版本,直接在后面指明版本号即可,例如:
yum install -y docker-ce-18.09.9

若要卸载docker:
yum remove -y docker-xxx

复制代码

 

复制代码

 5. 配置镜像加速器

 ——为什么需要镜像加速器?

 ——docker的镜像默认是从Docker hub下载,网速很慢,国内有很多云服务商都提供了加速器服务(阿里云加速器,Daocloud加速器,灵雀云加速器等)

复制代码
 


[root@VM-4-9-centos ~]# ##创建文件

复制代码
[root@VM-4-9-centos ~]# mkdir -p /etc/docker
[root@VM-4-9-centos ~]#
[root@VM-4-9-centos ~]# touch /etc/docker/daemon.json
[root@VM-4-9-centos ~]#
[root@VM-4-9-centos ~]# vim /etc/docker/daemon.json
[root@VM-4-9-centos ~]# cat /etc/docker/daemon.json

{
  "registry-mirrors":[
    "https://8xpk5wnt.mirror.aliyun.com"
  ]
}
复制代码

 

复制代码

 

6.  启动docker

systemctl daemon-reload  加载配置文件让其生效

[root@VM-4-9-centos ~]# systemctl daemon-reload
[root@VM-4-9-centos ~]# systemctl enable docker
[root@VM-4-9-centos ~]# systemctl restart docker

### 查看docker是否启动成功   

[root@VM-4-9-centos ~]# ps -ef|grep docker

  [root@VM-4-9-centos ~]# docker version

 

复制代码
[root@VM-4-9-centos ~]# ps -ef|grep docker

[root@VM-4-9-centos ~]# docker version
Client: Docker Engine - Community
Version: 20.10.15
API version: 1.41
Go version: go1.17.9
Git commit: fd82621
Built: Thu May 5 13:16:58 2022
OS/Arch: linux/amd64
Context: default
Experimental: true

Server: Docker Engine - Community
Engine:
Version: 20.10.6
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 8728dd2
Built: Fri Apr 9 22:43:57 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.4
GitCommit: 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16
runc:
Version: 1.1.1
GitCommit: v1.1.1-0-g52de29d
docker-init:
Version: 0.19.0
GitCommit: de40ad0

复制代码

 

posted @   麻花脑子里有很多问号  阅读(226)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示