Docker 安装手册
一、环境的检测和准备
uname -a
控制台输出:
Linux localhost.localdomain 3.10.0
-1160.21.1.el7.x86_64 #1 SMP Tue Mar 16 18:28:22 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
要求版本在3.8以上
cat /etc/redhat-release
控制台输出:
CentOS Linux release 7.9
.2009 (Core)
要求版本在7.6以上
getenforce
控制台输出:
Disabled
如果不是,执行命令:
vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
设置后需要重启才能生效
重启后执行:
systemctl stop firewalld
检查内存:内存需要大于2G
free -m
安装Base源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
安装epel源
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
安装yum utils
yum install -y yum-utils
更改yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装netstat -tools工具包
yum install net-tools
查看docker目录
yum list docker-ce --show-duplicates
二、安装docker
第一种:安装docker
rm -f /etc/yum.repos.d/local.repo
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
第二种:安装docker
yum install docker-ce
第四种:(rancher)
yum install wget net-tools telnet tree nmap sysstat lrzsz dos2unix bind-utils -y
rm -f /etc/yum.repos.d/local.repo
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
第五种:离线安装docker
1、解压并移动
tar zxvf docker-20.10.6.tgz
mv docker/* /usr/bin/
rm -rf docker(刚刚解压出的目录)
2、将docker注册为service
vi /etc/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
# 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
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
3、添加文件权限
chmod +x /etc/systemd/system/docker.service
======================================================================================
配置docker (此处开始为公共部分
)
mkdir /etc/docker/
mkdir -p /data/docker/
vi /etc/docker/daemon.json
\r\n转换\n
{
"graph":"/data/docker",
"storage-driver":"overlay2",
"insecure-registries":["registry.access.redhat.com","quay.io","192.168.43.33"],
"registry-mirrors":["https://q2gr04ke.mirror.aliyuncs.com"],
"bip":"172.43.32.1/24",
"exec-opts":["native.cgroupdriver=systemd"],
"live-restore":true
}
解释用:
{
//指定docker工作目录
"graph":"/data/docker",
//存储驱动
"storage-driver":"overlay2",
//不安全的私属仓库
"insecure-registries":["registry.access.redhat.com","quay.io"],
//阿里云加速源镜像
"registry-mirrors":["https://q2gr04ke.mirror.aliyuncs.com"],
//docker的网络(宿主机ip:192.168.43.101,建议有一定的关联性,便于后期维护)
"bip":"172.43.101.0/24",
//CUP内存控制组
"exec-opts":["native.cgroupdriver=systemd"],
//控制引擎与容器解耦(引擎死掉也不会影响容器)
"live-restore":true
}
启动配置文件
systemctl daemon-reload
设置开机启动docker
systemctl enable docker
启动docker
systemctl start docker
Docker启动命令1:
sudo systemctl start docker
Docker启动命令2:
sudo service docker start
Docker重启命令1:
sudo systemctl restart docker
Docker重启命令2:
sudo service docker restart
docker关闭命令1:
sudo systemctl stop docker
docker关闭命令2:
sudo service docker stop
守护进程重启:
sudo systemctl daemon-reload
设置Docker开机自启动方式1:
systemctl enable docker.service
设置Docker开机自启动方式2:
chkconfig docker on
关闭Docker开机启动:
systemctl disable docker.service
查看是否设置开机启动列表:
systemctl list-unit-files | grep enable
三、实例化第一个容器:Hello-World
执行:
docker run hello-world
至此成功