操作系统要求
- 64位安装,查看系统内核
uname -r - 版本 3.10 或更高版本的 Linux 内核,查看版本
sudo cat /etc/redhat-release - iptables版本 1.4 或更高版本
rpm -q iptables - docker守护进程,启用seccomp选项:
grep CONFIG_SECCOMP= /boot/config-$(uname -r),输出CONFIG_SECCOMP=y。
卸载旧版本
# 检查删除yum安装的dockersudo yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-engine# 检查docker相关文件夹,根据查找结果删除文件/文件夹find / -name docker
下载docker
docker官方下载地址:https://download.docker.com/linux/static/stable/x86_64/
这里选择的是ce版本即社区版
上传并解压
上传docker二进制文件到服务器,解压docker-18.06.3-ce.tgz获得docker文件夹,复制执行程序到/usr/bin目录下
tar -zxvf docker-18.06.3-ce.tgzcp docker/* /usr/bin/
创建docker.service和docker.socket
在/etc/systemd/system目录下创建docker.service和docker.socket,内容如下。
注:创建文件的原因是,二进制安装方式,缺少与系统的交互功能,也就是下文的systemctl操作docker。
[Unit]Description=Docker Application Container EngineDocumentation=https://docs.docker.comAfter=network-online.target firewalld.serviceWants=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 dockerExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sockExecReload=/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=infinityLimitNPROC=infinityLimitCORE=infinity# Uncomment TasksMax if your systemd version supports it.# Only systemd 226 and above support this version.#TasksMax=infinityTimeoutStartSec=0# set delegate yes so that systemd does not reset the cgroups of docker containersDelegate=yes# kill only the docker process, not all processes in the cgroupKillMode=process# restart the docker process if it exits prematurelyRestart=on-failureStartLimitBurst=3StartLimitInterval=60s[Install]WantedBy=multi-user.target
[Unit]Description=Docker Socket for the API[Socket]# If /var/run is not implemented as a symlink to /run, you may need to# specify ListenStream=/var/run/docker.sock instead.ListenStream=/run/docker.sockSocketMode=0660SocketUser=rootSocketGroup=docker[Install]WantedBy=sockets.target
启动docker
注:非root用户执行命令时,需在命令前输入 sudo
# 重启 systemctl 守护进程systemctl daemon-reload# 启动dockersystemctl start docker# 查看docker是否启动成功docker version# 设置开机自启,如下两条命令都可以systemctl enable dockersystemctl enable docker.service# 设置外开机自启后,输出如下内容,表示成功#Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to #/etc/systemd/system/docker.service.# 重启系统验证reboot# 启动后查看dockerdocker version# 停止dockersystemctl stop docker# 关闭开机自启,如下命令均可systemctl disable dockersystemctl disable docker.service
至此,docker环境安装完成!
