Launch maven webapp in docker container

I am trying to create a simple web application with Maven and work with Tomcat7 inside the Docker container.

This is my structure:

- Dockerfile - pom.xml - src/main/webapp/index.hmtl 

This is my Docker file:

 FROM java:8 # Install maven RUN apt-get -y update && apt-get install -y maven WORKDIR /code # Prepare by downloading dependencies ADD pom.xml /code/pom.xml # Adding source, compile and package into a fat jar ADD src /code/src RUN ["mvn", "package"] EXPOSE 8080 CMD ["mvn", "tomcat7:run"] 

I am creating a docker image using

 docker build -t webapp-example . 

and try running it with

 docker run -d -p 8080:8080 webapp-example 

But apparently this will not work.

Any ideas?

+6
source share
1 answer

Since you used a cooperative launch using tty and an interactive flag, for example, after solving your problem,

docker run -ti --rm -p 8080:8080 webapp-example

This is because your base java: 8 image, which is primarily created to run the application in front mode (with the -ti flag) or compiled only in -d mode.

Also, since maven is a build tool and should not be used to run the application, you should

  • Build a web application using maven: last image.
  • Deploy it separately as a tomcat container using the official tomcat image .
+4
source

Source: https://habr.com/ru/post/1015033/


All Articles