I'm trying to build a simple web app with Maven and run with Tomcat7, inside a Docker container.
This is my structure:
- Dockerfile
- pom.xml
- src/main/webapp/index.hmtl
This is my Dockerfile:
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'm building the Docker image with
docker build -t webapp-example .
and try to run it with
docker run -d -p 8080:8080 webapp-example
But apparently it doesn't work.
Any ideas?
Since you shared running using tty and interactive flag like following solves your problem,
docker run -ti --rm -p 8080:8080 webapp-example
That is because your base image is java:8 which is primarily created to run application in front mode (with -ti flag) or compile only in -d mode.
Also, since maven is build tools and should not be used to run application, you should,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With