An example of an docker image containing tomcat 8 and oracle jdk 8
- mvn clean install
- mvn tomcat7:run
mvn clean install -P docker
- First copy paste the war from target directory to target/docker directory
$ cp target/tomcat-docker-1.0.0-SNAPSHOT.war target/docker/
- Then build the docker image (it can take some time as it's curling oracle jdk and tomcat 8)
docker build -t tomcat-docker target/docker/
- Finally you're good to start the image in the background
docker run -d -p 8080:8080 tomcat-docker
- To connect in ssh to docker image with bash
docker exec -it ${IMAGE_ID_GENERATED_BY_DOCKER} bash
- To stop the container
docker stop $(docker ps -q --filter ancestor=tomcat-docker:1.0.0-SNAPSHOT)
http://localhost:8080/tomcatDocker/index.xhtml
Logs are written in docker image. /log/ for the application and /opt/tomcat/logs for tomcat. This is not a good practice, it is better to use a mount point to write logs on a NAS (check docker directive VOLUME to do that).