I've been playing around Docker since last year but stopped since I wasn't able to run Tomcat with it. After a year of not using it, I was suprised on how far it has gone! Installation on the Mac was straightforward and the selection of officially supported images in DockerHub has significantly improved.
You have two choices on installing Docker in OS X. I am using Yosemite so I am not sure if it also works with previous versions. But according to their website it does! You can either use Boot2Docker for those comfortable with CLI or Kitematic(also by Docker) for a visual interface.
Kitematic (DockerHub search)
Since most developers using CLI would know what to do, I'd just present how to run Tomcat using Kitematic. If you want to know how to do it using CLI, this documentation is a good start.
Going back on how to run Tomcat, what you need to do is search for Tomcat in Kitematic and look for the officially supported one.
Once you find it, you can click CREATE and it will download the Tomcat image for you and run a docker container based on that image automatically. If you don't choose a version, it will download the latest stable version.
So how do you choose a version to use? It's easy! You just need to click the ellipsis (three dots) button next to CREATE. It will show you select tag, click on that. Then, it'll show you this.
If you want to see all versions available you can check it out in DockerHub. Here is the link https://registry.hub.docker.com/_/tomcat/. It also has a brief guide on how to use it in CLI. Select a version you want. To run a container based the image, just click CREATE. Here is how mine looks like after clicking CREATE.
To know where to access Tomcat from the browser, just click on Settings tab in the right. Then click Ports. It will show you where your Tomcat is running.
Alternatively, you can go directly to Tomcat by clicking this icon
Yey! If you can see Tomcat's default page in your browser, congratulations! You did it! :)
One more thing, if you'd like Tomcat to use a webapps directory from your Host OS(your machine), just use this command in the CLI to run a container. Click DOCKER CLI to open a terminal.
Make sure your user has permissions for the directory you mounted. If you notice, I am not using the latest version since our project uses this combo Apache Tomcat 7.0.62 and Java 8.
docker run -d -P -v ~/webappsInMyMachine:/usr/local/tomcat/webapps --name custom-tomcat tomcat:7.0.62-jre8
After running this command, you can see that you'll have your local directory configured. You now can change it anytime from Kitematic. Isn't that cool? :)
That's it! Cheers and Happy Hacking!
Feel free to leave your comments below and share this to our fellow Java developers :)
Add me in LinkedIn
Subscribe to Melvin Vivas
Get the latest posts delivered right to your inbox