docker報(bào)錯(cuò)Container is not running問(wèn)題及解決
docker報(bào)錯(cuò)Container is not running
我在運(yùn)行docker exec -it 56b90db5253e /bin/bash
報(bào)錯(cuò)。
出現(xiàn)這個(gè)問(wèn)題,是因?yàn)?code>Container容器之前已經(jīng)啟動(dòng)過(guò)了
需要執(zhí)行docker start 56b90db5253e
就可以解決了。
docker啟動(dòng)失敗報(bào)錯(cuò)Failed to start Docker Application Container Engine
在給一臺(tái)騰訊云機(jī)器安裝docker后發(fā)現(xiàn)無(wú)法啟動(dòng),總是報(bào)錯(cuò)Failed to start Docker Application Container Engine,解決思路分享一下
安裝Docker
說(shuō)明:本文僅針對(duì)Linux CentOS 7環(huán)境下進(jìn)行講解,Mac版本請(qǐng)?jiān)诠俜较螺dDocker.dmg安裝(留意:Macbook 沒(méi)有yum、systemctl、service等Linux系統(tǒng)的命令,建議下載dmg桌面版Docker使用、配置方便。
當(dāng)然也可以brew install docker自己玩),Windows版本可以下載Docker exe安裝包。
卸載已有 Docker
如果你已經(jīng)安裝過(guò)舊版的 Docker,可以先執(zhí)行以下命令卸載舊版 Docker:
$ sudo yum remove docker \ ? ? ? ? ? ? ? ? ? docker-client \ ? ? ? ? ? ? ? ? ? docker-client-latest \ ? ? ? ? ? ? ? ? ? docker-common \ ? ? ? ? ? ? ? ? ? docker-latest \ ? ? ? ? ? ? ? ? ? docker-latest-logrotate \ ? ? ? ? ? ? ? ? ? docker-logrotate \ ? ? ? ? ? ? ? ? ? docker-engine
安裝 Docker
首次安裝 Docker 之前,需要添加 Docker 安裝源。添加之后,就可以從已經(jīng)配置好的源去 安裝和更新 Docker。
添加 Docker 安裝源的命令如下:
$ sudo yum-config-manager \ ? ? --add-repo \ ? ? https://download.docker.com/linux/centos/docker-ce.repo
正常情況下,直接安裝最新版本的 Docker 即可,因?yàn)樽钚掳姹镜?Docker 有著更好的穩(wěn)定性和安全性。
也可以使用以下命令安裝最新版本的 Docker:
$ sudo yum install docker-ce docker-ce-cli containerd.io
注意:Linux CentOS 版本可以通過(guò)uname -r 來(lái)查看,必須在3.10版本之上才可以使用新版docker。
比如我機(jī)器上的是3.10.0-1160.62.1.el7.x86_64。
如果想要安裝指定版本的 Docker,可以使用以下命令查看到一批最近的docker歷史版本列表:
$ sudo yum list docker-ce --showduplicates | sort -r
Repository epel is listed more than once in the configuration Loading mirror speeds from cached hostfile Loaded plugins: fastestmirror, langpacks Installed Packages docker-ce.x86_64 ? ? ? ? ? ?3:20.10.9-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.8-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.7-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.6-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.5-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.4-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.3-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.2-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.14-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.14-3.el7 ? ? ? ? ? ? ? ? ? @docker-ce-stable docker-ce.x86_64 ? ? ? ? ? ?3:20.10.1-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.13-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.12-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.11-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.10-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:20.10.0-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.9-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.8-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.7-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.6-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.5-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.4-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.3-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.2-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.15-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.14-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.1-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.13-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.12-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.11-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.10-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:19.03.0-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:18.09.9-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:18.09.8-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:18.09.7-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:18.09.6-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:18.09.5-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:18.09.4-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:18.09.3-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:18.09.2-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:18.09.1-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?3:18.09.0-3.el7 ? ? ? ? ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?18.06.3.ce-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?18.06.2.ce-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?18.06.1.ce-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?18.06.0.ce-3.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?18.03.1.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?18.03.0.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?17.12.1.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?17.12.0.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?17.09.1.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?17.09.0.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?17.06.2.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?17.06.1.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?17.06.0.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?17.03.3.ce-1.el7 ? ? ? ? ? ? ? ? ? docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?17.03.2.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?17.03.1.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable? docker-ce.x86_64 ? ? ? ? ? ?17.03.0.ce-1.el7.centos ? ? ? ? ? ?docker-ce-stable?
然后選取想要的版本執(zhí)行以下命令:
$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
安裝完成后,使用以下命令啟動(dòng) Docker。
$ sudo systemctl start docker
安裝完成后,我們需要使用以下命令啟動(dòng)一個(gè) hello world 的容器。
$ sudo docker run hello-world
如果看到輸出了【Hello from Docker!】則說(shuō)明docker可用。
其它命令比如docker ps -a查看所有鏡像,自行學(xué)習(xí)即可。
Docker安裝故障FAQ
安裝Docker的版本選擇
在Linux中對(duì)不同的安裝方式產(chǎn)生的安裝目錄和文件均不相同,有的會(huì)默認(rèn)放到/sbin或/opt或/usr/local下面,配置文件一般會(huì)在/etc下面。Docker也是一樣,如果使用:
sudo yum install docker
來(lái)安裝(建議均使用root權(quán)限),則安裝的版本為1.13.1。
而如果按照上述第一節(jié)的做法,安裝docker-ce版本,則最新是Docker version 20.10.14, build a224086。建議大家安裝docker-ce版本。
啟動(dòng)失敗
安裝完畢后,通過(guò)systemctl start docker啟動(dòng)直接報(bào)錯(cuò):
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
從這個(gè)錯(cuò)誤看不出來(lái)什么信息,就去看下運(yùn)行狀態(tài):
systemctl status docker:
[root@VM_17_5_centos init.d]# systemctl status docker ● docker.service - Docker Application Container Engine ? ?Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) ? ?Active: failed (Result: start-limit) since Sun 2022-04-10 19:09:56 CST; 11s ago ? ? ?Docs: https://docs.docker.com ? Process: 14592 ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE) ?Main PID: 14592 (code=exited, status=1/FAILURE) Apr 10 19:09:54 VM_17_5_centos systemd[1]: docker.service failed. Apr 10 19:09:56 VM_17_5_centos systemd[1]: docker.service holdoff time over, scheduling restart. Apr 10 19:09:56 VM_17_5_centos systemd[1]: Stopped Docker Application Container Engine. Apr 10 19:09:56 VM_17_5_centos systemd[1]: start request repeated too quickly for docker.service Apr 10 19:09:56 VM_17_5_centos systemd[1]: Failed to start Docker Application Container Engine. Apr 10 19:09:56 VM_17_5_centos systemd[1]: Unit docker.service entered failed state. Apr 10 19:09:56 VM_17_5_centos systemd[1]: docker.service failed. Apr 10 19:10:00 VM_17_5_centos systemd[1]: start request repeated too quickly for docker.service Apr 10 19:10:00 VM_17_5_centos systemd[1]: Failed to start Docker Application Container Engine. Apr 10 19:10:00 VM_17_5_centos systemd[1]: docker.service failed.
貌似也沒(méi)發(fā)現(xiàn)什么有效的錯(cuò)誤信息,唯一的一句錯(cuò)誤是【Failed to start Docker Application Container Engine.】網(wǎng)上其它文章的如下幾個(gè)解決方案均無(wú)法生效:
1)修改 /etc/docker/daemon.json添加registry-mirrors鏡像地址:這個(gè)是用于加速的,跟啟動(dòng)失敗一般不會(huì)有關(guān)系。
2)刪除/etc/docker/daemon.json:根本沒(méi)必要?jiǎng)h除,用docker官網(wǎng)的鏡像太慢了,肯定要配置國(guó)內(nèi)的鏡像源的。跟啟動(dòng)失敗也不會(huì)有關(guān)系。
3)修改Docker Container Engine的配置文件:
有的文章建議去修改/usr/lib/systemd/system/docker.service配置文件,個(gè)人覺(jué)得是根本沒(méi)有必要。雖說(shuō)從錯(cuò)誤信息看是有【Process: 14592 ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
Main PID: 14592 (code=exited, status=1/FAILURE)】這樣一句,但本質(zhì)上原生安裝包不可能剛安裝就有問(wèn)題還需要用戶自己修改什么。
鑒于上述幾點(diǎn)都無(wú)法解決,就想到查看Linux系統(tǒng)操作日志(最后200行就可以排查):
tail -200f /var/log/messages
此時(shí),再次輸入systemctl start docker試圖啟動(dòng)docker,發(fā)現(xiàn)如下錯(cuò)誤行:
dockerd: failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: Iptables not found
這句話的意思不就是iptables命令無(wú)法找到嗎?那試圖看下,cd /sbin目錄查找iptables,竟然的確沒(méi)有,用service iptables start也會(huì)報(bào)錯(cuò):iptables: /sbin/iptables does not exist。
但是,/sbin目錄下有個(gè)iptables_.sh文件??!是哪個(gè)應(yīng)用修改了這個(gè),不得而知,直接修改:
mv iptables_ iptables,再啟動(dòng):service iptables start,成功了!
這時(shí),再啟動(dòng)docker:systemctl start docker無(wú)輸出但沒(méi)報(bào)錯(cuò)了,通過(guò)systemctl status docker查看,狀態(tài)是Active狀態(tài),表示docker運(yùn)行正常了!
[root@VM_17_5_centos init.d]# systemctl status docker ● docker.service - Docker Application Container Engine ? ?Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled) ? ?Active: active (running) since Sun 2022-04-10 19:32:05 CST; 41min ago ? ? ?Docs: https://docs.docker.com ?Main PID: 16216 (dockerd) ? ? Tasks: 14 ? ?Memory: 38.3M ? ?CGroup: /system.slice/docker.service ? ? ? ? ? ?└─16216 /usr/bin/dockerd --containerd=/run/containerd/containerd.sock Apr 10 19:32:04 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:04.774479730+08:00" level=info msg="ccRes...=grpc Apr 10 19:32:04 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:04.774491097+08:00" level=info msg="Clien...=grpc Apr 10 19:32:04 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:04.800327122+08:00" level=info msg="[grap...lay2" Apr 10 19:32:04 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:04.805695934+08:00" level=info msg="Loadi...art." Apr 10 19:32:04 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:04.914702098+08:00" level=info msg="Defau...ress" Apr 10 19:32:05 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:05.027046047+08:00" level=info msg="Loadi...one." Apr 10 19:32:05 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:05.070391831+08:00" level=info msg="Docke...10.14 Apr 10 19:32:05 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:05.070498814+08:00" level=info msg="Daemo...tion" Apr 10 19:32:05 VM_17_5_centos systemd[1]: Started Docker Application Container Engine. Apr 10 19:32:05 VM_17_5_centos dockerd[16216]: time="2022-04-10T19:32:05.107225048+08:00" level=info msg="API l...sock" Hint: Some lines were ellipsized, use -l to show in full.
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
docker中配置hosts的方法實(shí)現(xiàn)
本文主要介紹了docker中配置hosts的方法實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04Docker 鏡像優(yōu)化(從1.16GB到22.4MB)
在這篇文章中,我將重點(diǎn)討論如何優(yōu)化 Docker 鏡像以使其輕量化,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08Ubuntu15.10安裝docker和docker-compose教程
這篇文章主要介紹了Ubuntu15.10安裝docker和docker-compose的教程,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03基于alpine用dockerfile創(chuàng)建的tomcat鏡像的實(shí)現(xiàn)
這篇文章主要介紹了基于alpine用dockerfile創(chuàng)建的tomcat鏡像的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-12-12Docker 安裝 MySQL 并實(shí)現(xiàn)遠(yuǎn)程連接教程
這篇文章主要介紹了Docker 安裝 MySQL 并實(shí)現(xiàn)遠(yuǎn)程連接的教程,幫助大家更好的理解和使用docker容器,感興趣的朋友可以了解下2020-09-09