Grails应用程序在本地运行,但不会在Docker容器中运行

时间:2018-03-20 20:03:08

标签: java docker tomcat grails dockerfile

我有一个用Grails 3.3构建的应用程序,我正试图在Docker容器中运行。我正在使用简单的grails package命令构建应用程序,该命令在项目的build / libs目录中创建一个WAR文件。我没有使用任何选项来构建一个自包含的可执行JAR文件。但是,我发现我仍然可以使用以下命令直接启动应用程序:

java -jar -Dgrails.env=prod -Dserver.port=9000 build/libs/myapp-0.1.war

直接从我的本地机器(终端)运行时,这实际上工作正常。该应用程序需要大约一分钟才能启动,但最终确实如此,我在终端中看到了这条消息:

  

Grails应用程序在环境中的http://localhost:9000运行:生产

但是,我试图在Docker容器中复制相同的设置,并在那里失败。这是我正在使用的Dockerfile:

FROM java:8
RUN mkdir -p /app
COPY ./build/libs/myapp-0.1.war /app
WORKDIR /app
EXPOSE 80
ENTRYPOINT ["java"]
CMD ["-jar", "-Dgrails.env=prod", "-Dserver.port=80", "myapp-0.1.war"]

我使用docker build -t myapp:latest .构建Docker镜像,然后尝试使用docker run -p 9000:80 -it myapp:latest运行它。它似乎启动,就像在本地运行时一样。但是,它不可避免地会发出类似于此错误消息:

Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException.
Message: Error creating bean with name 'logoutFilterDeregistrationBean':
Cannot resolve reference to bean 'logoutFilter' while setting bean property 'filter';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'logoutSuccessHandler':
Cannot resolve reference to bean 'redirectStrategy' while setting bean property 'redirectStrategy';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'redirectStrategy':
Cannot resolve reference to bean 'myCustomService' while setting bean property 'myCustomService';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'myCustomService': Initialization of bean failed;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'myCustomService': Unsatisfied dependency expressed through field 'dao';
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'com.mydomain.custom.MyCustomDao' available:
expected at least 1 bean which qualifies as autowire candidate.

***************************
APPLICATION FAILED TO START
***************************

Description:

Field dao in com.mydomain.custom.MyCustomService required a bean of type 'com.mydomain.custom.MyCustomDao' that could not be found.

Action:

Consider defining a bean of type 'com.mydomain.custom.MyCustomDao' in your configuration.

对我来说,用于启动WAR文件的相同命令(java -jar在我的本地计算机上工作但不会< / em>在Docker容器中工作。对我而言,这意味着java:8基本映像缺少本地系统运行此WAR文件所需的内容。关于不自动连接bean的错误在我看来有点像红色鲱鱼,并且与正在发生的任何真正问题无关(因为当我在本地运行时不会发生自动回线问题)。有什么想法吗?

0 个答案:

没有答案