发布网友 发布时间:2024-09-07 01:13
共1个回答
热心网友 时间:2024-09-07 02:26
前言服务器重做了centos7.5版本的操作系统,剩下就是安装Docker,考虑yum安装耗时较长,我一般都是直接安装二进制版本docker包,下面我们看下如何离线部署docker
安装步骤国际惯例,看说明书选版本说明书传送门:https://docs.docker.com/engine/install/binaries/里面有一项比较重要的说明:
Version3.10orhigheroftheLinuxkernel.Thelatestversionofthekernelavailableforyourplatformisrecommended.不过我们已经升级了centos7.5,看了一下内核版本
uname-r3.10.0-862.el7.x86_64看着没有什么问题,docker二进制包下载地址:https://download.docker.com/linux/static/stable/x86_64/,挑来挑去,准备装前个版本最后的stable版本:docker-19.03.9.tgz,这个版本我们用的也比较多
开始安装解压压缩包
建个目录,我的是/home/docker,把压缩文件放在目录里,执行tarzxvfdocker-19.03.9.tgz
生成docker服务文件
cat>/etc/systemd/system/docker.service<<"EOF"[Unit]Description=DockerApplicationContainerEngineDocumentation=http://docs.docker.io[Service]Environment="PATH=/home/docker/docker:/bin:/sbin:/usr/bin:/usr/sbin"ExecStart=/home/docker/docker/dockerd--log-level=error-Hunix:///var/run/docker.sockExecReload=/bin/kill-sHUP$MAINPIDRestart=on-failureRestartSec=5LimitNOFILE=infinityLimitNPROC=infinityLimitCORE=infinityDelegate=yesKillMode=process[Install]WantedBy=multi-user.targetEOF生成docker配置文件
sudoiptables-PFORWARDACCEPTmkdir-p/etc/docker/cat>/etc/docker/docker-daemon.json<<EOF{"insecure-registries":["192.xx.xx.8:5000","registry.xxx.com"],"registry-mirrors":["https://jk4bb75a.mirror.aliyuncs.com","https://docker.mirrors.ustc.edu.cn"],"max-concurrent-downloads":20}EOF启动docker
systemctlstopfirewalld&&systemctldisablefirewalld/usr/sbin/iptables-F&&/usr/sbin/iptables-X&&/usr/sbin/iptables-F-tnat&&/usr/sbin/iptables-X-tnat/usr/sbin/iptables-PFORWARDACCEPTsystemctldaemon-reload&&systemctlenabledocker&&systemctlrestartdockerforintfin/sys/devices/virtual/net/docker0/brif/*;doecho1>$intf/hairpin_mode;doneexportPATH=/home/docker/docker/:$PATHPS:exportPATH=/home/docker/docker/:$PATH可以写到/etc/profile文件中
确认docker是否正常
systemctlstatusdocker.service查看docker状态,确保是running。
如果有问题,修改service文件,然后重启
systemctldaemon-reload&&systemctlrestartdocker.service一切看起来是十分的完美,国际惯例,没病走两步,运行hello-world试下:
dockerrunhello-worlddocker:Errorresponsefromdaemon:OCIruntimecreatefailed:container_linux.go:345:startingcontainerprocesscaused"process_linux.go:430:containerinitcaused\"write/proc/self/attr/keycreate:permissiondenied\"":unknown.ERRO[0000]errorwaitingforcontainer:contextcanceledFirstWTF!
OCIruntimecreatefailed问题定位与解决官网文档里搜一把传送门:https://docs.docker.com/
随便点开几个看了一下,系统版本不一样,但是说的都是一个事,操作系统内核版本和docker版本不对应,升级内核或降低版本,不是说好的3.10内核版本是可以的吗?都正常启动了
降版本至docker-18.09.9,仍然失败下载docker-18.09.9.tgz,解压覆盖docker文件夹,直接重启即可一切看起来是十分的完美,没病走两步,运行hello-world试下:
dockerrunhello-worlddocker:Errorresponsefromdaemon:OCIruntimecreatefailed:container_linux.go:xxx:startingcontainerprocesscaused"process_linux.go:xxx:containerinitcaused\"write/proc/self/attr/keycreate:permissiondenied\"":unknown.ERRO[0000]errorwaitingforcontainer:contextcanceledDoubleWTF!
降版本至docker-18.06.3下载docker-18.06.3-ce.tgz,解压覆盖docker文件夹,直接重启即可
dockerrun--rmhello-worldHellofromDocker!Thismessageshowsthatyourinstallationappearstobeworkingcorrectly.Togeneratethismessage,Dockertookthefollowingsteps:1.TheDockerclientcontactedtheDockerdaemon.2.TheDockerdaemonpulledthe"hello-world"imagefromtheDockerHub.(amd64)3.TheDockerdaemoncreatedanewcontainerfromthatimagewhichrunstheexecutablethatproducestheoutputyouarecurrentlyreading.4.TheDockerdaemonstreamedthatoutputtotheDockerclient,whichsentittoyourterminal.Totrysomethingmoreambitious,youcanrunanUbuntucontainerwith:$dockerrun-itubuntubashShareimages,automateworkflows,andmorewithafreeDockerID:https://hub.docker.com/Formoreexamplesandideas,visit:https://docs.docker.com/get-started/令人亲切的hello-world终于出来了
总结Centos7的内核版本默认都是3.10系列,我这边两个3.10.0-862内核版本的系统安装18.09和19.03都能正常启动,但是就是无法正常运行容器,不升级内核只能安装18.06版本,这边还有一台机器是centos7.7,内核版本是3.10.0-1062.18.1.el7.x86_6,是可以正常跑docker19.03版本的,仅供参考,如果运行容器出现OCIruntimecreatefailed优先考虑系统内核版本兼容性问题,早期的Ubuntu安装新版本的docker也有这样的问题,一般也是降版本或升级内核解决。