CentOS下Docker安装部署


1.CentOS 安装和删除Docker
https://docs.docker.com/install/linux/docker-ce/centos/
2.下载rpm包安装:
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
3.阿里镜像下载地址:
https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/
一.安装和删除Docker

//通过yum源安装:
由于官网的yum源太慢,下面使用阿里云的Yum源进行安装

rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo (或https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo  /http://mirrors.163.com/docker-ce/linux/centos/docker-ce.repo)
yum clean all 
yum -y install docker-ce
systemctl enable --now docker
二.Linux 二进制安装

//本方法适用于无法上网的主机安装docker

1.安装文档:
https://docs.docker.com/install/linux/docker-ce/binaries/
2.二进制安装下载路径
https://download.docker.com/linux/
https://mirrors.aliyun.com/docker-ce/linux/static/stable/x86_64/
3.下载二进制文件
https://download.docker.com/linux/static/stable/x86_64/docker-18.03.1-ce.tgz
4.解压二进制文件
tar xzvf docker-18.03.1-ce.tgz
5.复制二进制文件到/usr/bin目录下
cp docker/* /usr/bin/
6.检查是否安装
docker version
7.配置 docker.service文件
vi /usr/lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target
8.启动dockerd服务进程
systemctl daemon-reload
systemctl start docker.service
9.检验
ps aux|grep docker
docker run hello-world

//或

wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz
tar zxf docker-18.06.3-ce.tgz
cp docker/* /usr/bin/

cat > /usr/lib/systemd/system/docker.service <<"EOF"
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl restart docker
systemctl enable docker
10.确认docker安装成功
docker version
三. 配置镜像加速器

//针对Docker客户端版本大于 1.10.0 的用户
您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://un1tt4qx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
四.更改docker的数据目录
sudo mkdir /data
sudo cp -ar /var/lib/docker/ /data/

sudo vim  /etc/docker/daemon.json
{
"registry-mirrors": ["https://un1tt4qx.mirror.aliyuncs.com"],
"graph":"/data/docker"
}

sudo systemctl daemon-reload
sudo systemctl restart docker
五.开启缓存收集yum安装rpm包
vim /etc/yum.conf
.............................
keepcache=1

mkdir docker_rpm
find /var/cache/yum/x86_64/7/ -name "*.rpm" -type f |xargs -i mv {} docker_rpm/
ls docker_rpm/
tar zcf docker_rpm.tar.gz docker_rpm
scp xxxxxx
yum localinstall *.rpm -y

systemctl start docker
systemctl enable docker
docker --version
六.安装指定版本的Docker-CE:

//Step 1: 查找Docker-CE的版本:

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

//Step2: 安装指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)

yum -y install docker-ce-[VERSION]
七.删除旧版本docker
sudo yum remove docker /
              docker-client /
              docker-client-latest /
              docker-common /
              docker-latest /
              docker-latest-logrotate /
              docker-logrotate /
              docker-engine

sudo yum -y remove docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/267307.html

(0)
上一篇 2022年6月15日 02:58
下一篇 2022年6月15日 03:07

相关推荐

发表回复

登录后才能评论