Dockerize Apache Tomcat on Windows

This stackoverflow post [1] explains how it is possible to build and run an image for Java Web Application on Tomcat, via Docker, but if you are working on Windows, probably it is not going to work for you, because you may face with

cannot enable tty mode on non tty input. [2]

Let’s try something to get over this.

* Create a folder in Desktop as “docky”.
* Copy your war file to “docky”.
* Create a file without file extension called “Dockerfile”.

FROM tomcat
MAINTAINER xyz

ADD yourApp.war /usr/local/tomcat/webapps/

CMD ["catalina.sh", "run"]

Do NOT change “/usr/local/tomcat/webapps/” part. Just replace “yourApp.war” with name of your actual war file.

Open C:\Program Files\Docker Toolbox.
Run start.sh to start Docker.
After MINGW64 is opened go to “docky” in command line.

Type command:

docker build -t yourName .

Don’t forget “.” at the end. “.” shows path of Dockerfile.

If you type

docker run --rm -it -p 8080:8080 yourName

to start Tomcat, exception is shown which is mentioned above.

docky0.png

Now open Oracle VM VirtualBox.
Double click default VM to open.
Please read instructions on popup before click Next/OK/Capture etc.

After VM is ready you can type

docker run --rm -it -p 8080:8080 yourName

to start Tomcat.

To exit from VM, press “Right Ctrl” on keyboard.

So Tomcat is running in VM, but how can we access it?

Right click to default VM > Settings > Network > NAT in Oracle VM VirtualBox screen.
Click “Port Forwarding”.
Add new record as

TCP 127.0.0.1 8080 8080

docky1docky2docky3

So 8080 port of your VM is linked to your PC’s 8080 port.

Now open your browser and go to http://localhost:8080/ and you should see default Tomcat page.
Lastly try http://localhost:8080/yourApp and I hope it works!

[1] http://stackoverflow.com/questions/27818856/docker-add-warfile-to-official-tomcat-image

[2] https://github.com/docker/docker/issues/12469

[3] https://x86x64.wordpress.com/2015/05/03/docker-on-windows-fata0021-an-error-occurred-trying-to-connect/

[4] http://stackoverflow.com/questions/27471688/how-to-access-tomcat-running-in-docker-container-from-browser

[5] http://trimc-devops.blogspot.com.tr/2015/03/running-docker-applications-apache.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: