docker源码下载
[root@localhost ~]# cd /usr/local/
[root@localhost local]# wget -c http://mirrors.163.com/docker-ce/linux/static/stable/x86_64/docker-20.10.6.tgz
解压
[root@localhost local]# tar -xf docker-20.10.6.tgz
[root@localhost local]# useradd -s /sbin/nologin docker -M
[root@localhost local]# cat>>/etc/profile<<EOF
export PATH=\$PATH:/usr/local/docker/
EOF
[root@localhost local]# mkdir /etc/docker
[root@localhost local]# cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
],
"registry-mirrors": ["https://uyah70su.mirror.aliyuncs.com"]
}
EOF
启动
[root@localhost local]# cd docker
复制所有可执行文件至/usr/bin目录下,为启动服务做准备
[root@localhost docker]# cp -rf * /usr/bin/
手动启动
[root@localhost docker]# nohup /usr/local/docker/dockerd >/usr/local/docker/nohup.out >/dev/null 2>&1 &
[root@localhost docker]# docker --version
Docker version 20.10.6, build 370c289
[root@localhost local]# wget -c https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64
[root@localhost local]# mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
[root@localhost local]# chmod a+x /usr/local/bin/docker-compose
[root@localhost local]# ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
看版本
[root@localhost ~]# docker-compose --version
docker-compose version 1.29.2, build 5becea4c
systemd 启动脚本
[root@localhost ~]# vim /etc/systemd/system/docker.service
[Unit]
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
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl restart docker
脚本
if [ $UID -ne 0 ];then
echo "username is not root,please use root,now exit"
exit
fi
cd /usr/local/
echo "download docker-19.03.0.tgz, wait......"
wget -c http://mirrors.163.com/docker-ce/linux/static/stable/x86_64/docker-20.10.7.tgz
tar -xf docker-20.10.7.tgz
useradd -s /sbin/nologin docker -M
echo "set docker path"
cat>>/etc/profile<<EOF
export PATH=\$PATH:/usr/local/docker/
EOF
mkdir /etc/docker
echo "daemon.json"
cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
],
"registry-mirrors": ["https://uyah70su.mirror.aliyuncs.com"]
}
EOF
cd docker
echo "cp -rf * /usr/bin/"
cp -rf * /usr/bin/
echo "show version"
docker --version
echo "download docker-compose"
wget -c https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64
mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
chmod a+x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
echo "docker.sevice in systemd"
cat > /etc/systemd/system/docker.service <<EOF
[Unit]
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
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
echo "reload daemon"
systemctl daemon-reload
echo "restart docker"
systemctl restart docker
docker ps
注:
1、如果连接本地harbor仓库
cat /etc/docker/daemon.json ,最后加上insecure-registries行,别忘记了前一行的逗号
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
],
"registry-mirrors": ["https://uyah70su.mirror.aliyuncs.com"],
"insecure-registries":["192.168.2.100:1080"]
}
2、如在docker容器中安装docker时
#yum模式
yum install -y yum-utils iptables -y
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum install docker-ce docker-ce-cli containerd.io
也可以安装指定版本
yum install docker-ce-20.10.7 docker-ce-cli-20.10.7 containerd.io -y
docker run -itd --privileged -p 80:80 -v /data/docker_nginx:/sys/fs/cgroup --name=nginx nginx:latest
#二进制模式
yum install iptables yum-utils -y
yum upgrade -y
#安装以上脚本,这里忽略
#wget -c http://mirrors.163.com/docker-ce/linux/static/stable/x86_64/docker-20.10.7.tgz
docker run -itd --privileged --name=del -v /data/docker_nginx:/sys/fs/cgroup/ nginx:latest
----------------------end