The most common exit codes, what they mean, and what causes them

Sandeep Madamanchi

Follow

Oct 21, 2019 · 4 min read

Docker container exit code — how to use them for troubleshooting?

It’s one of the most common question that I come across: “Why is my container not running?”

Can docker container exit codes help troubleshoot this issue?

The first step in answering this question is to identify the exit code for the docker container. The exit code may give a hint as to what happened to stop the container running. This article lists the most common exit codes when working with docker containers and aims to answer two important questions:

  • What does this specific exit code mean?
  • What action caused this exit code?

This will ultimately help answer the original question: “Why is my container not running?”


How to Find Exit Codes

Option 1: List all containers that exited

docker ps --filter "status=exited"

Option 2: Grep by container name

docker ps -a grep <container-name>Example: docker ps -a | grep hello-world

Option 3: Inspect by container id

docker inspect <container-id> --format='{{.State.ExitCode}}'Example: docker inspect ca6cbb290468 --format='{{.State.ExitCode}}'

Exit Codes

Common exit codes associated with docker containers are:

  • Exit Code 0: Absence of an attached foreground process
  • Exit Code 1: Indicates failure due to application error
  • Exit Code 137: Indicates failure as container received SIGKILL (Manual intervention or ‘oom-killer’ [OUT-OF-MEMORY])
  • Exit Code 139: Indicates failure as container received SIGSEGV
  • Exit Code 143: Indicates failure as container received SIGTERM

Exit Code 0

  • Exit code 0 indicates that the specific container does not have a foreground process attached.
  • This exit code is the exception to all the other exit codes to follow. It does not necessarily mean something bad happened.
  • Developers use this exit code if they want to automatically stop their container once it has completed its job.

Here is an example using the public docker container — “hello-world”. If you have docker installed on your system or VM instance, run this:

docker run hello-world

You will get a message, “Hello from docker!” but try to find the container using this code:

docker ps -a | grep hello-world

You’ll notice that the container exited and the exit code is 0. This is because the container does not have any foreground process attached, such as a Java process or a shell process that runs until a SIGTERM event occurs

Exit code 0

Exit Code 1

  • Indicates that the container stopped due to either an application error or an incorrect reference in Dockerfile to a file that is not present in the container.
  • An application error can be as simple as “divide by 0” or as complex as “Reference to a bean name that conflicts with existing, non-compatible bean definition of same name and class.”
  • An incorrect reference in Dockerfile to a file not present in the container can be as simple as a typo (the example below has sample.ja instead of sample.jar)

Exit Code 1

Exit Code 137

  • This indicates that container received SIGKILL
  • A common event that initiates a SIGKILL is a docker kill. This can be initiated either manually by user or by the docker daemon:
docker kill <container-id>
  • docker kill can be initiated manually by the user or by the host machine. If initiated by host machine, then it is generally due to being out of memory. To confirm if the container exited due to being out of memory, verify docker inspect against the container id for the section below and check if OOMKilled is true (which would indicate it is out of memory):
"State": {"Status": "exited","Running": false,"Paused": false,"Restarting": false,"OOMKilled": true,"Dead": false,"Pid": 0,"ExitCode": 137,"Error": "","StartedAt": "2019-10-21T01:13:51.7340288Z","FinishedAt": "2019-10-21T01:13:51.7961614Z"
}

Exit Code 139

  • This indicates that container received SIGSEGV
  • SIGSEGV indicates a segmentation fault. This occurs when a program attempts to access a memory location that it’s not allowed to access, or attempts to access a memory location in a way that’s not allowed.
  • From the Docker container standpoint, this either indicates an issue with the application code or sometimes an issue with the base images used by the container.

Exit Code 143

  • This indicates that container received SIGTERM.
  • Common events that initiate a SIGTERM are docker stop or docker-compose stop. In this case there was a manual termination that forced the container to exit:
docker stop <container-id>
OR
docker-compose down <container-id>
  • Note: sometimes docker stop can also result in exit code 137. This typically happens if the application tied to the container doesn’t handle SIGTERM — the docker daemon waits ten seconds then issues SIGKILL

Some uncommon exit codes with Docker containers (typically with shell script usage)

  • Exit Code 126: Permission problem or command is not executable
  • Exit Code 127: Possible typos in shell script with unrecognizable characters

Understanding Docker Container Exit Codes相关推荐

  1. docker container

    docker 容器操作 常用 参数 描述 -a,–attach list Attach to STDIN, STDOUT or STDERR -c,–cpu-shares int CPU shares ...

  2. Docker - Docker Container及Container命令详解

    Docker - Docker Container及Container命令详解 什么是Docker容器(Docker Container) 上一篇博客介绍了Docker镜像(Docker Image) ...

  3. 6.docker container

    1. 什么是container 通过 image 创建 (copy得到的) 在 image layer (在image 层) 上 增加了一层 container layer (container 层 ...

  4. Docker Container介绍

    1.什么是Container 通过Image创建(copy) 在Image layer之上建立一个container layer(可读写) 类比面向对象: 类和实例 Image负责app的储存和发行, ...

  5. Docker Container同时启动多服务 supervisor

    Docker Container同时启动多服务 转载请注明来自:http://blog.csdn.net/wsscy2004 昨天踩了个天坑,我有一个基本的镜像centos6.5+ssh,是通过Doc ...

  6. Docker源码分析(八):Docker Container网络(下)

    http://www.infoq.com/cn/articles/docker-source-code-analysis-part8 1.Docker Client配置容器网络模式 Docker目前支 ...

  7. Docker源码分析(七):Docker Container网络 (上)

    http://www.infoq.com/cn/articles/docker-source-code-analysis-part7 1.前言(什么是Docker Container) 如今,Dock ...

  8. Docker container与宿主进程相互隔离的实现原理

    我们都知道在Docker container里运行ps命令是看不到宿主机上运行的进程的.这种程度的隔离是通过什么方式实现的呢? 答案是Linux内部命令unshare. 我第一次执行命令unshare ...

  9. 把设备分享给每个Docker Container

    本文分析如何把设备分享给每个Docker Container使用. 假设我有一个设备,通过/dev/my_device进行访问,现在我启动一个Docker container,需要访问这个设备,最简单 ...

最新文章

  1. 如何使用gensim来加载和使用词向量模型word2vec
  2. linux系统启动过程(三)
  3. HDU 1010 Tempter of the Bone DFS(奇偶剪枝优化)
  4. 如何编写nopCommerce插件
  5. c/c++笔试面试题(4)
  6. linux 关闭setitimer_Linux定时器函数setitimer
  7. C++ 动态命名和修改变量名 动态生成变量名 define
  8. stm32的命名及选型介绍
  9. html5 预览dwg,哪个企业网盘可以实现dwg在线预览?
  10. couchbase php,CouchBase + PHP 安装与配置
  11. 可以说是迄今为止最好用的右键菜单管理工具
  12. 国内薪水最高的IT公司排行榜TOP25,大家都说说你们觉得这数据准确吗,我怎么觉得不太准确。。
  13. linux 网卡绑定解绑,网卡绑定开机绑定,关机解绑
  14. MinGW到底是个什么ghost
  15. Longest Substring with Same Letters after Replacement (hard)
  16. C#语言入门、xamarin基础、.NET MAUI全栈开发技术综合笔记
  17. 【有效防范“网络钓鱼”的方法】
  18. ALIENTEK探索者STM32F407时钟树
  19. 音视频开发-音视频面试必问的直播延迟分析丨FFmpeg|SRS流媒体服务器|webrtc|Android NDK开发|HTTP-FLV|RTSP
  20. 如何理解卷积神经网络中的权值共享

热门文章

  1. Mybatis(一)之概述
  2. URLEncoder前置处理器
  3. TDEngine 用户管理
  4. [转]国内计算机牛校评点
  5. Homestead环境搭建及简介
  6. PGP(Pretty Good Privacy)
  7. python爬虫数据无法插入到数据库中
  8. 【WPS表格】表格左右列/上下行内容互换位置
  9. GNN-CS224W: 4 Link Analysis: PageRank
  10. python图形界面化编程GUI(五)坦克大战(一)