Ishant Gaurav
Ishant Gaurav

Reputation: 1203

Deploy simple standalone spring mvc application in docker container

I have to deploy simple standalone spring mvc application in docker container. I started with this application and haven't been able to find a solution to deploy it within docker.

My Dockerfile:

FROM tomcat:8.0.20-jre8
COPY spring-mvc-example.war /usr/local/tomcat/webapps/

I am getting the following error when I execute

sudo docker run -p 8080:8080 springmvc

ERROR

org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/spring-mvc-example]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:917)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1701)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@77c87bba]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4840)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4970)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more
Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.JarResourceSet@27179421]
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:139)
    at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:699)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 13 more
Caused by: java.lang.IllegalArgumentException: java.util.zip.ZipException: invalid CEN header (bad signature)
    at org.apache.catalina.webresources.JarResourceSet.initInternal(JarResourceSet.java:96)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    ... 16 more
Caused by: java.util.zip.ZipException: invalid CEN header (bad signature)
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:220)
    at java.util.zip.ZipFile.<init>(ZipFile.java:150)
    at java.util.jar.JarFile.<init>(JarFile.java:166)
    at java.util.jar.JarFile.<init>(JarFile.java:103)
    at org.apache.catalina.webresources.JarResourceSet.initInternal(JarResourceSet.java:88)
    ... 17 more

30-Mar-2018 18:33:40.268 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive /usr/local/tomcat/webapps/spring-mvc-example.war
 java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/spring-mvc-example]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:728)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:917)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1701)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Upvotes: 2

Views: 1995

Answers (2)

Ishant Gaurav
Ishant Gaurav

Reputation: 1203

I found the solution , seems like it was because of the some corrupted files in my local repository.

I deleted all the files in local maven repository and downloaded them again. and followed the same steps as above then was able to deploy the war successfully.

Upvotes: 2

Stefan Crain
Stefan Crain

Reputation: 2060

I was able to get the example project working. Here are the steps I took to package it.

Download the zip file of the project from here. Unzip and build the project.

cd /path/to/spring-mvc-example
mvn package

Copy the spring-mvc-example.war from the /path/to/spring-mvc-example/targets/spring-mvc-example.war file into the folder with your Dockerfile

My Dockerfile

FROM tomcat:8.0.20-jre8
COPY spring-mvc-example.war /usr/local/tomcat/webapps/

Build your docker file

docker build -t so-49579717 .

Run your container.

docker run -p 8080:8080 so-49579717

I don't see any of the errors you did above. As you didn't mention the maven package step, maybe you were trying to package the zip file into the container?

Upvotes: 0

Related Questions