您好,登錄后才能下訂單哦!
本篇內容介紹了“Docker無法正常啟動的原因是什么及如何解決”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
一、docker啟動異常表現:
1.狀態反復restaring,用命令查看
$docker ps -a container id image command created status ports names 21c09be88c11 docker.xxxx.cn:5000/xxx-tes/xxx_tes:1.0.6 "/usr/local/tomcat..." 9 days ago restarting (1) less than a second ago xxx10
2.docker日志有明顯問題:
$docker logs [容器名/容器id]
二、docker啟動異常的可能原因:
2.1.內存不夠
docker 啟動至少需要2g內存,首先執行free -mh命令查看剩余內存是否足夠
直接查看內存
$free -mh total used free shared buff/cache available mem: 15g 14g 627m 195m 636m 726m swap: 0b 0b 0b
分析日志
有時候一瞬間內存過載溢出,導致部分進程被殺死,看起來內存也是夠用的,事實上docker還是會反復重啟,就需要通過docker日志和系統日志信的息來進一步分析:
分析docker日志
查看docker日志看到內存溢出的信息,要仔細翻閱才能找到信息,并不是在最下面
$docker logs [容器名/容器id]|less java hotspot(tm) 64-bit server vm warning: info: os::commit_memory(0x0000000769990000, 1449590784, 0) failed; error='cannot allocate memory' (errno=12) # # there is insufficient memory for the java runtime environment to continue. # native memory allocation (malloc) failed to allocate 1449590784 bytes for committing reserved memory. # an error report file with more information is saved as: # //hs_err_pid1.log java hotspot(tm) 64-bit server vm warning: info: os::commit_memory(0x0000000769990000, 1449590784, 0) failed; error='cannot allocate memory' (errno=12) # # there is insufficient memory for the java runtime environment to continue. # native memory allocation (malloc) failed to allocate 1449590784 bytes for committing reserved memory. # an error report file with more information is saved as: # /tmp/hs_err_pid1.log java hotspot(tm) 64-bit server vm warning: info: os::commit_memory(0x0000000769990000, 1449590784, 0) failed; error='cannot allocate memory' (errno=12) # # there is insufficient memory for the java runtime environment to continue. # native memory allocation (malloc) failed to allocate 1449590784 bytes for committing reserved memory. # can not save log file, dump to screen.. # # there is insufficient memory for the java runtime environment to continue. # native memory allocation (malloc) failed to allocate 1449590784 bytes for committing reserved memory. # possible reasons: # the system is out of physical ram or swap space # in 32 bit mode, the process size limit was hit # possible solutions: # reduce memory load on the system # increase physical memory or swap space # check if swap backing store is full # use 64 bit java on a 64 bit os # decrease java heap size (-xmx/-xms) # decrease number of java threads # decrease java thread stack sizes (-xss) # set larger code cache with -xx:reservedcodecachesize= # this output file may be truncated or incomplete. # # out of memory error (os_linux.cpp:2756), pid=1, tid=140325689620224 # # jre version: (7.0_79-b15) (build ) # java vm: java hotspot(tm) 64-bit server vm (24.79-b02 mixed mode linux-amd64 compressed oops) # core dump written. default location: //core or core.1 #
分析系統日志
查看系統日志,發現有大量由于內存溢出,進程被殺死的記錄
$grep -i 'out of memory' /var/log/messages apr 7 10:04:02 centos106 kernel: out of memory: kill process 1192 (java) score 54 or sacrifice child apr 7 10:08:00 centos106 kernel: out of memory: kill process 2301 (java) score 54 or sacrifice child apr 7 10:09:59 centos106 kernel: out of memory: kill process 28145 (java) score 52 or sacrifice child apr 7 10:20:40 centos106 kernel: out of memory: kill process 2976 (java) score 54 or sacrifice child apr 7 10:21:08 centos106 kernel: out of memory: kill process 3577 (java) score 47 or sacrifice child apr 7 10:21:08 centos106 kernel: out of memory: kill process 3631 (java) score 47 or sacrifice child apr 7 10:21:08 centos106 kernel: out of memory: kill process 3634 (java) score 47 or sacrifice child apr 7 10:21:08 centos106 kernel: out of memory: kill process 3640 (java) score 47 or sacrifice child apr 7 10:21:08 centos106 kernel: out of memory: kill process 3654 (java) score 47 or sacrifice child apr 7 10:27:27 centos106 kernel: out of memory: kill process 6998 (java) score 51 or sacrifice child apr 7 10:27:28 centos106 kernel: out of memory: kill process 7027 (java) score 52 or sacrifice child apr 7 10:28:10 centos106 kernel: out of memory: kill process 7571 (java) score 42 or sacrifice child apr 7 10:28:10 centos106 kernel: out of memory: kill process 7586 (java) score 42 or sacrifice child
2.2.端口沖突
該docker監聽端口已經被其他進程占用,一般此種問題容易出現在新部署的服務,或在原有機器上部署新的后臺服務,所以在部署之前應該執行命令檢查端口是否已經被占用,如果上線后發現占有則應改為可用端口再重啟之。
檢查命令: $netstat -nltp|grep [規劃的端口號]
三、對策
3.1.內存不夠的對策:
對策1:
3.1.1 saltstack的minion在運行過久之后,可能占用大量內存,需要將其重啟。重啟命令可能有時并不起作用。主要檢查運行狀態,如果未成功停止,則重新重啟;
對策2:
3.2.2 elk日志收集程序或者其他java進程占用過高,用top和ps命令排查,謹慎確定進程的作用,在確保不影響業務的情況下,停止相關進程;
對策3:
釋放被占用的內存(buff/cache):
$sync #將內存數據寫入磁盤
$echo 3 > /proc/sys/vm/drop_caches #釋放被占用的內存
對策4:
有時候并不是buff/cache過高導致內存不夠用,確實是被很多必要的進程消耗掉了內存,那就需要從機器資源分配使用的層面去考慮和解決了。
3.2 端口沖突的對策
對策1:
一般此種問題容易出現在新部署的服務,或在原有機器上部署新的后臺服務,所以在部署之前應該執行命令檢查端口是否已經被占用,如果上線后發現占有則應改為可用端口再重啟之。
檢查命令: $netstat -nltp|grep [規劃的端口號]
“Docker無法正常啟動的原因是什么及如何解決”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。