在centos上安装过docker的都知道,yum install docker ,这种方式安装的docker,最新版的centos系统上,版本应该是1.13.1,而目前最新版的docker到了18.03.0了。那么怎么安装最新版的docker-ce呢?
1、系统要求
Linux操作系统内核要不低于3.10,并且要支持systemd。
2、下载最新版的docker
Docker官网下载地址:https://download.docker.com/linux/static/stable/x86_64/
上面列出了docker-ce版本,根据自己需要下载对应版本的docker-ce.
Docker官网下载地址:https://download.docker.com/linux/static/stable/x86_64/
我下载的是18.03.0版本。
3、安装部署方式说明
整个安装部署过程大致可分为将介质解压出docker目录、将可执行文件copy到/usr/bin目录并设置权限、设置docker的systemd设定文件、设定docker服务开机启动等。
方便的是,已经有志愿者将所有安装命令整理成一个脚本,直接下载下来执行即可。
脚本下载地址:
https://github.com/liumiaocn/easypack/blob/master/docker/install-docker.sh
#!/bin/sh
usage(){
echo "Usage: $0 FILE_NAME_DOCKER_CE_TAR_GZ"
echo " $0 docker-18.03.0--ce.tgz"
echo "Get docker-ce binary from: https://download.docker.com/linux/static/stable/x86_64/"
echo "eg: wget https://download.docker.com/linux/static/stable/x86_64/docker-18.03.0--ce.tgz"
echo ""
}
SYSTEMDDIR=/usr/lib/systemd/system
SERVICEFILE=docker.service
DOCKERDIR=/usr/bin
DOCKERBIN=docker
SERVICENAME=docker
if [ $# -ne 1 ]; then
usage
exit 1
else
FILETARGZ="$1"
fi
if [ ! -f ${FILETARGZ} ]; then
echo "Docker binary tgz files does not exist, please check it"
echo "Get docker-ce binary from: https://download.docker.com/linux/static/stable/x86_64/"
echo "eg: wget https://download.docker.com/linux/static/stable/x86_64/docker-18.03.0--ce.tgz"
exit 1
fi
echo "##unzip : tar xvpf ${FILETARGZ}"
tar xvpf ${FILETARGZ}
echo
echo "##binary : ${DOCKERBIN} copy to ${DOCKERDIR}"
cp -p ${DOCKERBIN}/* ${DOCKERDIR} >/dev/null 2>&1
which ${DOCKERBIN}
echo "##systemd service: ${SERVICEFILE}"
echo "##docker.service: create docker systemd file"
cat >${SYSTEMDDIR}/${SERVICEFILE} <<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target docker.socket
[Service]
Type=notify
EnvironmentFile=-/run/flannel/docker
WorkingDirectory=/usr/local/bin
ExecStart=/usr/bin/dockerd \
-H tcp://0.0.0.0:4243 \
-H unix:///var/run/docker.sock \
--selinux-enabled=false \
--log-opt max-size=1g
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=on-failure
[Install]
WantedBy=multi-user.target
EOF
echo ""
systemctl daemon-reload
echo "##Service status: ${SERVICENAME}"
systemctl status ${SERVICENAME}
echo "##Service restart: ${SERVICENAME}"
systemctl restart ${SERVICENAME}
echo "##Service status: ${SERVICENAME}"
systemctl status ${SERVICENAME}
echo "##Service enabled: ${SERVICENAME}"
systemctl enable ${SERVICENAME}
echo "## docker version"
docker version
4、安装部署
1、上传文件并设置执行权限,将脚本和文件放在同一级目录。
chmod +x install-docker.sh # 授予可执行权限
2、执行安装命令
./install-docker.sh docker-18.03.0-ce.tgz
安装过程最后,脚本会执行docker version命令来显示docker的版本。