运行docker镜像,出现Exited (137) 5 seconds ago问题
Posted 覃会程
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了运行docker镜像,出现Exited (137) 5 seconds ago问题相关的知识,希望对你有一定的参考价值。
通过docker ps -a
命令查看容器状态,发现状态为:
Exited (137) 5 seconds ago
然后使用docker logs -f container_id
命令查看日志信息,发现是代码有错:
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/blockchain/management/BlockchainManagementApplication has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:92)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:45)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:86)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
然后idea中调试代码,能正常启动,并查看dockerfile如下:
# Docker image for springboot file run
# VERSION 0.0.1
# Author: eangulee
# 基础镜像使用java
FROM repository.gridsum.com:8443/library/maven:3.6.2-jdk-8 as builder
# 作者
MAINTAINER autogeneration
# VOLUME 指定了临时文件目录为/tmp。
# 其效果是在主机 /var/lib/docker 目录下创建了一个临时文件,并链接到容器的/tmp
VOLUME /tmp
# 将jar包添加到容器中并更名为app.jar
ADD management-0.0.1-SNAPSHOT.jar app.jar
# 运行jar包
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
重新制作镜像,再次运行,还是出现相同的错误
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/blockchain/management/BlockchainManagementApplication has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:92)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:45)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:86)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
产生问题的原因:
经过查询,发现是pom.xml的使用的jdk版本和dockerfile中的builder不一致
pom.xml使用的是11,buidler使用的是8
解决问题:
将buidler中的版本修改为11,然后再一次制作镜像,启动容器,最终成功启动,状态为Up
在浏览器访问成功:
以上是关于运行docker镜像,出现Exited (137) 5 seconds ago问题的主要内容,如果未能解决你的问题,请参考以下文章