ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

CentOS下Docker安装部署

2022-06-09 11:31:38  阅读:396  来源: 互联网

标签:CentOS 部署 sudo ce yum https Docker com 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

标签:CentOS,部署,sudo,ce,yum,https,Docker,com,docker
来源: https://www.cnblogs.com/yanghaizhen/p/16358642.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有