Docker学习(一)- 环境搭建(centos7下搭建)

1、装一个centeros7虚拟机,我的版本如下(如何装虚拟机自行百度)

#uname -a
#Linux 33_du 3.10.0-rt56 #1 SMP PREEMPT RT Tue Jan 8 17:02:27 CST 2019 x86_64 x86_64 x86_64 GNU/Linux

2、关闭防火墙,不关的话需要配置iptables规则那些,为了方便直接关闭了

# systemctl stop firewalld
# systemctl disable firewalld

3、关闭swap

vi /etc/fstab

 注释里面的"/dev/mapper/centos-swap swap"

 验证:

说明:

1.swap相当于“虚拟内存”。当物理内存不足时,拿出部分硬盘空间当SWAP分区(虚拟成内存)使用,从而解决内存容量不足的情况
2.kubelet 在 1.8 版本以后强制要求 swap 必须关闭
3.free -m 命令可以查看交换区的空间大小,我们注释完再使用这个命令发现交换区swap还没关闭,因为需要重启才生效

4、关闭selinux(selinux这个是用来加强安全性的一个组件,挺复杂的,一般直接禁用,关闭selinux以允许容器访问宿主机的文件系统)

vi /etc/selinux/config

注释掉SELINUX=disabled,然后重启,reboot

5、添加阿里源

# rm -rfv /etc/yum.repos.d/*
# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

 6、配置主机名(可选,不用k8s可以不做这步)

hostnamectl set-hostname test

查看主机名

more /etc/hostname

7、 配置内核参数,将桥接的IPv4流量传递到iptables的链(可选,不用k8s可以不做这步

[root@test ~]cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

 8、使用aliyun源安装docker-ce(yum-config-manager命令配置aliyun源,但是这个命令来源于yum-utils,所以需要先安装yum-utils)

[root@test ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@test ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@test ~]# yum -y install docker-ce

安装完docker后添加aliyun的docker仓库加速器

[root@test~]# mkdir -p /etc/docker
[root@test~]# tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://fl791z1h.mirror.aliyuncs.com"]
}
EOF
[root@test~]# systemctl daemon-reload
[root@test~]# systemctl restart docker

9、测试

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值