This is going to be the first part of a series of posts where I'm going to document my journey containerizing our Platform.
Here's the story so far:
First Forays
The beginning of this journey was extremely haphazard (aka, I was bored one night and wanted something to work on while watching TV). For fun I spun up a Server 2016 box with our software installed on it and set up Docker on Windows since (due to our Customers) our Platform is Windows first.
Once that was all done, I copied the .wars that make up our admin application and the distribution of tomcat that we use and threw all of that into a Dockerfile and spun it up to talk to the SQL Server instance installed on that box.
It was pretty cool to type docker run
and connect to that tomcat instance and see it work. Server 2016 Dockerfile
It's all fun to get this to work on Windows, but lets face it, Windows is a limiting factor when all the new developments in DevOps treats Windows as a Second Class Citizen at best.
Moving Forward
Those first steps were done back in November of 2018 and I eventually picked this back up in May of 2019.
This is when I started to want to get more serious about my personal projects and wanting to learn more about containers and take learning Docker more seriously.
Deploying our wars to linux
This is where things get really fun.
With the help of my awesome co-worker Valerie answering my really basic questions, I got things working.
The nice thing about Java is the WORA (write once, run anywhere) principal it follows. For the most part the initial getting things working was a case of pulling the image for Tomcat 8.5.40 and building my container by writing another pretty basic Dockerfile. Linux Dockerfile
After some trial and error and tracking down dependencies (jar with the SQL Server driver, a mail library) to get things working, I got a connection to an existing database on another server, and authentication via LDAP that was already pre-configured in that database.
Getting our webapps to work on Linux has been fun, because I'm getting to learn more about Tomcat. For the most part, the server.xml is a static entity but there are items that I want to be able to pass to the container as it starts up. Mainly the DB connection string and information.
That's where I learned how to use the \$JAVA_OPTS to populate variables in the server.xml.
docker run -it -p 80:8080 -e "JAVA_OPTS=$JAVA_OPTS -Ddbserver=sql1" --net test mhb/heartbeat:1.0
Is what I've been using to launch the tomcat container with the environment variable to set the JAVA_OPTS environment variable in the container.
With -e "JAVA_OPTS=$JAVA_OPTS -Ddbserver=sql1"
option, that sets the \$JAVA_OPTS environment variable in the container. Within the server.xml I have access to the dbserver variable that I can set with \${dbserver}.
The next iteration of this is going to involve learning the setenv.sh script so I can use environment files in my compose file so I can more securly set the variables.
Coming up with a task list
Once I saw that working, I came up with a list of tasks to go from the most basic of POC to an actual MVP that I can show off and see what people think.
- Get SQL Server on Linux working in Docker
- Figure out how to run our Flyway migrations in Docker
- Wire everything up in docker
- Perform builds and deploy to Docker
- Docker Compose
Now I have a task list to work through