Docker:18.x版本安裝與卸載


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://help.aliyun.com/document_detail/60742.html?spm=5176.10695662.1996646101.searchclickresult.49a821betEeRPU


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM