代码改变世界

Docker:18.x版本安装与卸载(1.1)

2019-08-02 17:14  huoit  阅读(1711)  评论(0编辑  收藏  举报

Docker CE 分为 stable, test, 和 nightly 三个更新频道。每六个月发布一个 stable 版本

 

初始化机器

#1、关闭警报
vi /etc/inputrc

#然后将set bell-style none前面的#删掉 none 改为 off

#:wq 保存退出

vim /etc/bashrc

#在开始的地方加上一句 setterm -blength 0

#:wq

# 2、ip
cd /etc/sysconfig/network-scripts/
vi ifcfg-ens33

#3.要修改的数据,没有则新增----------------------按键A插入修改,:wq!保存退出
BOOTPROTO=static            ### 手动设置IP
#UUID=...                   ### 注释掉UUID方便后面clone虚拟机
IPADDR=192.168.19.200        ### 本机IP 为 192.168.19.200
NETMASK=255.255.255.0       ### 子网掩码
GATEWAY=192.168.19.2         ### 默认网关 对应我们NAT设置里查看的网关IP
DNS1=8.8.8.8                ### DNS 设置为Google的
ONBOOT=yes                  ### 开机


#关闭防火墙
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl stop firewalld.service && systemctl disable firewalld.service

#修改时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
sudo echo 'LANG="en_US.UTF-8"' >> /etc/profile;source /etc/profile
yum -y install ntp ntpdate
ntpdate cn.pool.ntp.org
hwclock --systohc
date -R

#优化
cat >> /etc/sysctl.conf<<EOF
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
EOF

 

#主机名命名
hostnamectl --static set-hostname  rancher
#增加host
echo '192.168.11.200    rancher192.168.11.201   ranchermaster' >> /etc/hosts

 

 

安装docker脚本

#!/bin/sh
# 1 关闭防火墙
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl stop firewalld.service && systemctl disable firewalld.service
yum remove -y $(rpm -qa | grep docker)
# 1.1卸载旧版本Docker软件
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux  docker-engine-selinux docker-engine container*
rm -rf /etc/systemd/system/docker.service.d
rm -rf /var/lib/docker
rm -rf /var/run/docker
# 1.2:localtime
#ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#echo 'LANG="en_US.UTF-8"' >> /etc/profile;source /etc/profile
# -------开始---------
# 定义用户名
NEW_USER=rancher
# 添加用户(可选)
sudo adduser $NEW_USER
# 为新用户设置密码
sudo passwd $NEW_USER
# 为新用户添加sudo权限
sudo echo "$NEW_USER ALL=(ALL) ALL" >> /etc/sudoers
# 定义安装版本
export docker_version=18.06.3
# step 1: 安装必要的一些系统工具
sudo yum update -y;
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 bash-completion;
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo;
#sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#yum-config-manager --enable docker-ce-nightly
#yum-config-manager --disable docker-ce-nightly
#yum makecache fast
# Step 3: 更新并安装 Docker-CE
sudo yum makecache all;
version=$(yum list docker-ce.x86_64 --showduplicates | sort -r|grep ${docker_version}|awk '{print $2}');
sudo yum -y install --setopt=obsoletes=0 docker-ce-${version} docker-ce-selinux-${version};
# 如果已经安装高版本Docker,可进行降级安装(可选)
#yum downgrade --setopt=obsoletes=0 -y docker-ce-${version} docker-ce-selinux-${version};
# 把当前用户加入docker组
sudo usermod -aG docker $NEW_USER;
# 设置开机启动
sudo systemctl start docker;
sudo systemctl enable docker.service;

 

启动

 

# systemctl start docker
# systemctl enable docker.service

 

新版卸载

yum remove docker-ce

#删除镜像、卷……
rm -rf /var/lib/docker

 

 windows下编辑sh文件,上传后需要转换格式

 

1.修改为可执行文件 :chmod +x test.sh。
2.“:set ff=unix” 或 “:set fileformat=unix” 修改解析器(Windows下编辑保存的文件默认是doc解析)。
3.“:x” 或 “:wq”保存退出。

 

官方安装脚本

https://github.com/rancher/install-docker 

 

资源:

https://help.aliyun.com/document_detail/60742.html?spm=5176.10695662.1996646101.searchclickresult.49a821betEeRPU