Docker Tomcat 8

Posted onby admin

April 16, 2019

Sudo docker run -d -p 8080:8080 -name tomcat catyku/tomcat:8.5-jre8. And then use a different Tomcat-based Docker container to deploy the application. We’ll cover both approaches next. Install Tomcat on the existing Maven-based image. Create an empty directory and add a Dockerfile inside it with the following content.

I’m in the process of trying out a Tomcat server that’s running JDK 11 and rather than deal with multiple VM’s on my machine for the moment I want to try the server out locally in a isolated environment.

So packaged with Java 8 but running on Java 11.

To do that Docker made sense. Set up a docker container with Tomcat 9 and JDK 11.

So first is to set up IntelliJ to connect to your docker install, on a Mac this seemed nice and straight forward. Guide here

That’s covered here. Now the settings for this is where the real fun is. Seems from the interface the ‘Bind Mounts’ are only happy with directories. Having a maven build the war was a file within the target directory, so I created a new artifact that was the war in it’s own directory and has a stable name (i.e. the version isn’t tacked on) the name is the context path so this is handy I think.

Not sure the best way for setting up the settings for Tomcat within the container. The app ran out of memory straight away so first port of call was adding JAVA_OPTS to the environment variables section.

Next was setting up a database connection, this seemed less clean. I added a volume mount for the whole config directory using the settings copied from a local install. So that’s

It then needs the driver (in this case Oracle). Rather than mount the whole lib folder which seems like the only option under Bind Mounts I added a volume definition to the Run Options section

So started getting there now. For some reason it failed with a TimeZone error

Must be something different from the local setting and the docker setup, back to JAVA_OPTS and add -Duser.timezone=GMT

So it now runs and I can attempt to hammer the app config until it’s happy to run on 8 and 11 as we transition. The thing is though a Spring Boot application runs very very slowly way slower than if it was a local install. I haven’t nailed it yet but some of these magic sauce options make it better but not great. Added to JAVA_OPTS

Random is a known performance problem as there just isn’t enough entropy in the container. Normal warnings apply to urandom (it isn’t full secure) but the performance on startup is still pretty poor.

Update

So it seems the slowness is a known issue and it’s to do with Docker on the Mac, Spring and Tomcat are innocent I tried the cached setting explained here but it made no real difference. If you copy the war into a new image and run that container it extremely fast, but that seems like quite the pain.

Further update

So in the end what worked is to volume mount the war file to a file in the webapps folder. You can’t do this using the bind mounts as mentioned above so add it to the Run Options. It now starts in about 2 seconds as opposed to 25 plus

Written by David Kerwick who lives and works Dublin as a Java Technical Lead.

April 16, 2019

I’m in the process of trying out a Tomcat server that’s running JDK 11 and rather than deal with multiple VM’s on my machine for the moment I want to try the server out locally in a isolated environment.

So packaged with Java 8 but running on Java 11.

To do that Docker made sense. Set up a docker container with Tomcat 9 and JDK 11.

So first is to set up IntelliJ to connect to your docker install, on a Mac this seemed nice and straight forward. Guide here

That’s covered here. Now the settings for this is where the real fun is. Seems from the interface the ‘Bind Mounts’ are only happy with directories. Having a maven build the war was a file within the target directory, so I created a new artifact that was the war in it’s own directory and has a stable name (i.e. the version isn’t tacked on) the name is the context path so this is handy I think.

Not sure the best way for setting up the settings for Tomcat within the container. The app ran out of memory straight away so first port of call was adding JAVA_OPTS to the environment variables section.

Next was setting up a database connection, this seemed less clean. I added a volume mount for the whole config directory using the settings copied from a local install. So that’s

It then needs the driver (in this case Oracle). Rather than mount the whole lib folder which seems like the only option under Bind Mounts I added a volume definition to the Run Options section

So started getting there now. For some reason it failed with a TimeZone error

Must be something different from the local setting and the docker setup, back to JAVA_OPTS and add -Duser.timezone=GMT

So it now runs and I can attempt to hammer the app config until it’s happy to run on 8 and 11 as we transition. The thing is though a Spring Boot application runs very very slowly way slower than if it was a local install. I haven’t nailed it yet but some of these magic sauce options make it better but not great. Added to JAVA_OPTS

Docker Ubuntu Tomcat 8

Random is a known performance problem as there just isn’t enough entropy in the container. Normal warnings apply to urandom (it isn’t full secure) but the performance on startup is still pretty poor.

Docker Tomcat 8080 404

Docker tomcat 8080 404

Update

Docker Tomcat 9

So it seems the slowness is a known issue and it’s to do with Docker on the Mac, Spring and Tomcat are innocent I tried the cached setting explained here but it made no real difference. If you copy the war into a new image and run that container it extremely fast, but that seems like quite the pain.

Further update

So in the end what worked is to volume mount the war file to a file in the webapps folder. You can’t do this using the bind mounts as mentioned above so add it to the Run Options. It now starts in about 2 seconds as opposed to 25 plus

Docker Tomcat Image

Written by David Kerwick who lives and works Dublin as a Java Technical Lead.