docker RPM包官方网址:https://download.docker.com/linux/centos/7/x86_64/stable/Packages/
docker tar包官方网址:https://download.docker.com/linux/static/stable/x86_64/
#配置本地yum源
cd /etc/yum.repos.d/
#判断光盘是否挂载
[ -d /media/cdrom ] || mkdir /media/cdrom
mount | grep sr0 &> /dev/null
[ $? -eq 0 ] || mount /dev/sr0 /media/cdrom
echo "光盘已挂载"
#安装使用包
yum -y install wget net-tools psmisc gcc gcc-c++ make unzip which
mv CentOS-Base.repo CentOS-Base.repo.bak
#配置网络yum源
[ -f CentOS7-Base-163.repo ] || wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[ -f Centos-7.repo ] || wget http://mirrors.aliyun.com/repo/Centos-7.repo
[ -f epel-testing.repo ] || wget http://mirrors.aliyun.com/repo/epel-testing.repo
[ -f epel-7.repo ] || wget http://mirrors.aliyun.com/repo/epel-7.repo
[ -f epel.repo ] || wget http://mirrors.aliyun.com/repo/epel.repo
yum clean all && yum makecache
yum install -y yum-utils
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
#yum-utils提供了yum-config-manager 效用,并device-mapper-persistent-data和lvm2由需要 devicemapper 存储驱动程序
yum install -y yum-utils
yum install -y device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all
yum makecache
yum list docker-ce --showduplicates | sort -r
yum -y install docker-ce-19.03.5 docker-ce-cli-19.03.5 containerd.io
systemctl start docker
docker version
Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:25:41 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:24:18 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.3
GitCommit: 269548fa27e0089a8b8278fc4fc781d7f65a939b
runc:
Version: 1.0.0-rc92
GitCommit: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
docker-init:
Version: 0.18.0
GitCommit: fec3683
[root@localhost images]# cat /etc/docker/daemon.json
{
"data-root": "/data/docker",
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["http://hub-mirror.c.163.com"], #国内镜像源
"insecure-registries": ["docker.erick.com:5000"], #私有仓库
"log-driver": "json-file",
"log-opts": {
"max-size": "100m", #每个容器日志文件大小
"max-file": "10" #最多生成的文件数
}
}
wget https://download.docker.com/linux/static/stable/x86_64/docker-19.03.3.tgz
tar xf docker-19.03.3.tgz
cd docker
ll ./
[root@localhost docker]# ll
总用量 204696
-rwxr-xr-x 1 cka cka 34625816 10月 8 2019 containerd
-rwxr-xr-x 1 cka cka 6116160 10月 8 2019 containerd-shim
-rwxr-xr-x 1 cka cka 18850136 10月 8 2019 ctr
-rwxr-xr-x 1 cka cka 65641747 10月 8 2019 docker
-rwxr-xr-x 1 cka cka 72067152 10月 8 2019 dockerd
-rwxr-xr-x 1 cka cka 764144 10月 8 2019 docker-init
-rwxr-xr-x 1 cka cka 2877369 10月 8 2019 docker-proxy
-rwxr-xr-x 1 cka cka 8649800 10月 8 2019 runc
cp docker/* /usr/bin/
PS:因为启动文件中的命令取自/usr/bin
**查看docker版本**
**docker version**
[root@localhost ~]# docker version
Client: Docker Engine - Community
Version: 19.03.3
API version: 1.40
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 00:54:52 2019
OS/Arch: linux/amd64
Experimental: false
**Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?**
表示找不到docker.sock,docker服务未启动
vim /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
# 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
>chmod +x /lib/systemd/system/docker.service
systemctl daemon-reload //重载systemd下 xxx.service文件
systemctl start docker //启动Docker
systemctl enable docker.service //设置开机自启
[root@localhost ~] docker version
Client: Docker Engine - Community
Version: 19.03.3
API version: 1.40
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 00:54:52 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.3
API version: 1.40 (minimum version 1.12)
Go version: go1.12.10
Git commit: a872fc2f86
Built: Tue Oct 8 01:01:20 2019
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
#!/bin/bash
set -x
tar_name=docker-19.03.3.tgz
#var
unamer=`uname -r |cut -d'.' -f1-2`
#kernel 3.10+
if [[ $unamer -lt 3.10 ]];then
echo "the linux kernel too lower" && exit 8
fi
#setup
tar xf $tar_name && mv docker/* /usr/bin/ && rm -rf docker*
#systemd config
cat >/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
#start
chmod +x /etc/systemd/system/docker.service
systemctl daemon-reload && systemctl start docker && systemctl enable docker.service
#look docker.service
systemctl status docker && docker -v