How Do You Deploy Apache Tomcat in a Docker Instance in an AWS Ubuntu Linux Server?

Problem scenario
You want to deploy Apache Tomcat in a Docker container on an AWS instance of Ubuntu Linux.  How do you do this?

1.  Install Docker.  See this link if you need assistance.
2.  Start the Docker service with this command:  sudo service docker start
3.  Run these two commands:

docker pull consol/tomcat-8.0
docker run consol/tomcat-8.0

4.  The second of the above commands will appear to hang.  Start a new Putty session to the Ubuntu server.  Continue with the directions below and leave both Putty instances up.

docker ps -a  #get the alphanumeric Docker container ID
docker inspect -f format='{{.NetworkSettings.IPAddress}}' abcd1234

#where abcd1234 is the container ID found above

# Note the IP address of the second of the above commands  You will use it again soon.

5.  Optional step if you want to use the web UI of Tomcat.  Create a second Docker container with Nginx inside it, and configure Nginx as a load balancer to distribute traffic to the Tomcat instance.  Follow these directions if you want to do this.  For step #6.d. in those directions refers to IP addresses where you want the traffic to go to.  You will have one IP address to add in the upstream block.  It will appear after the word "server", and it will be a socket for the IP address obtained in step #4 above with a :8080 at the end.  For example, step 6.d. in the Nginx in a Docker Container as an HTTP Load Balancer directions will leave you with something like this at the end of the default.conf file:

upstream {

6.  Optional step if you did step #5 above.  You'll need to stop and start the Nginx Docker container for it to take effect.  Test it by opening a web browser and going to the external IP address of the server with these docker containers.  To find this, on the back-end of the server and outside of a Docker container, run the command "curl".  Open a web browser on a desktop that has access to this server, and go to the IP address obtained from the curl command above.

Leave a comment

Your email address will not be published. Required fields are marked *