详解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 [规划的端口号]

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • Docker容器的创建、启动、和停止的方法

    1.容器是独立运行的一个或一组应用,及他们的运行环境.容器是Docker中的一个重要的概念. 2.docker容器的启动有三种方式 a.交互方式,基于镜像新建容器并启动 例如我们可以启动一个容器,打印出当前的日历表 [root@rocketmq-nameserver4 ~]# docker run my/python:v1 cal ##my/python:v1为镜像名和标签 我们还可以通过指定参数,启动一个bash交互终端. [root@rocketmq-nameserver4 ~]# dock

  • Docker容器自启动的实现方法

    容器自启动 Docker提供了restart policy机制,可以在容器退出或者Docker重启时控制容器能够自启动.这种Restart policy可以保证相关容器按照正确顺序启动.虽然也可以通过进程监控的方式(如systemd)来完成这种动作,但Docker还是建议尽量避免使用进程监控的方式来 "自启动" 容器. Docker的 Restart policy与dockerd命令的--live-restore启动标志还有区别:--live-restore标志可以在Docker升级的

  • CentOS7 安装docker 解决启动不了的问题

    CentOS7安装docker 启动不了,在工作当中遇到这个问题,当时急的不清,网上资料又不多,不过经过自己的捣鼓终于解决了 这个问题! [root@test ~]# yum update [root@test ~]# yum install docker [root@test ~]# service docker start Redirecting to /bin/systemctl start docker.service Job for docker.service failed beca

  • 两种方式创建docker镜像的启动容器时区别介绍(总结篇)

    Docker是建立在Linux内核基础上的,在目前的主流Linux系统中,都已经原生支持了Docker且使用体验也最好,当然,在Windows平台和MacOS系统中也支持Docker,只是需要使用类似Boot2Docker等虚拟化工具来提供Linux支持. 下面重点给大家介绍基于两种创建docker镜像的启动容器时区别,感兴趣的朋友可以跟着小编一起学习! 1.凡是用docker commit生成的镜像启动的时候可以加载一个启动自己应用的脚本,例如: docker run -d -P tomcat

  • Docker容器内应用服务自启动的方法示例

    如果想把Docker容器内的应用服务随着容器开启时自启动.只需要将服务启动的脚本写在Dockerfile里,然后用Dockerfile重构镜像即可实现: 编写应用服务自启动脚本 编写Dockerfile 重构镜像 开启容器 编写服务自启动脚本(dockerd) (tomcat为例) #!/bin/bash # # # # chkconfig: 345 98 30 # description: tomcat program. # processname: tomcat # Source funct

  • Docker如何同时启动多个服务

    前几篇Docker的文章介绍启动容器时都是只启动一个后台服务,今天来说说怎样通过supervisor来启动多个服务 1. 首先创建一个目录并在目录下创建一个Dockerfile,文件内容如下 FROM centos:centos6 MAINTAINER Fanbin Kong "kongxx@hotmail.com" RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rp

  • 详解Docker如何启动一个Centos镜像

    接着上文,我们下载完成一个Centos镜像之后,开始启动 #运行命令 docker run -d -i -t <imageID> /bin/bash 这样就能启动一个一直停留在后台运行的Centos了.如果少了/bin/bash的话,Docker会生成一个Container但是马上就停止了,不会一致运行即使有了-d参数. 然后我们可以进入我们这个Centos docker attach <ContainerID> 进入Centos后,发现竟然没有ifconfig和ssh,网上例子很

  • CentOS7 docker服务无法启动解决方案及实现步骤

    CentOS7  docker服务无法启动解决方案 检查步骤 启动docker服务: systemctl restart docker 这个时候会报错,请进行以下步骤: 1. 找到报错的类型,或者报错的说明. 2. 检查docker的配置文件 3. 检查磁盘空间 4. 检查端口占用情况 步骤详解 检查报错类型,查看日志: journalctl -xe 检查配置文件,不同操作系统位置基本相同: /etc/sysconfig/docker/ 或者直接找到docker运行程序,一般会有相关配置文件的默

  • Docker如何进入启动容器

    本文介绍了Docker如何进入启动容器,分享给大家,具体如下: 在使用-d参数时,容器启动后会进入后台,用户无法看到容器中的信息,也无法进行操作. 这个时候如果需要进入容器进行操作,有多种方法,包括使用官方的attach或exec命令,以及第三方的nsenter工具等. 1.attach命令 attach命令是Docker自带的命令,命令格式为: docker attach [–detach-keys[=[]]] [–no-stdin] [–sig-proxy[=true]] Container

  • docker中mysql初始化及启动失败问题解决方案

    最近做项目,遇到这样问题,docker 中的mysql 不能启动,经过上网查资料,终于解决了这个问题,这里记录下,也许还能帮助到大家, 在docker中有一个mysql服务,其数据文件是挂在在主机外面的文件,在docker中的root有访问该数据文件的权限,但是docker中mysql访问数据文件的时候提示权限不足,于是只有以root用户来启动mysql了. 数据初始化: mysql_install_db --user=root --explicit_defaults_for_timestamp

随机推荐