Cloud Native 9 min read

Build a Tomcat Runtime on Docker: A Complete Step‑by‑Step Tutorial

This guide walks through installing Docker on Ubuntu, configuring user permissions, pulling a tutorial image, setting up SSH, installing JDK and Tomcat inside the container, and exposing ports so you can access a Tomcat server via the host, demonstrating a simple PaaS setup.

ITPUB
ITPUB
ITPUB
Build a Tomcat Runtime on Docker: A Complete Step‑by‑Step Tutorial

Docker provides an automated way to deploy applications in lightweight containers, separating production and development environments. This tutorial shows how to create a Tomcat runtime inside Docker on an Ubuntu 13.10 server.

Environment

The host is a 64‑bit Ubuntu 13.10 server running in VMware Workstation.

Install Docker (0.7)

sudo apt-get update
sudo apt-get install linux-image-extra-$(uname -r)
sudo sh -c "wget -qO- https://get.docker.io/gpg | apt-key add -"
sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
sudo apt-get update
sudo apt-get install lxc-docker
sudo docker version

# verify installation

Remove the need for sudo

sudo groupadd docker
sudo gpasswd -a yongboy docker

# replace yongboy with your login name

sudo service docker restart
docker version

# should work without sudo

Pull and Run a Tutorial Image

docker pull learn/tutorial
docker run learn/tutorial /bin/echo hello world
docker run -i -t learn/tutorial /bin/bash

# enter interactive shell

Inside the container you see a prompt like root@51774a81beb3:/#, confirming you are in the interactive environment.

Install SSH Server in the Container

apt-get update
apt-get install openssh-server
which sshd

# should return

/usr/sbin/sshd
mkdir /var/run/sshd
passwd

# set a password (e.g., 123456) for SSH login

exit

Commit the Container as a New Image

docker ps -l

# obtain the container ID, e.g.,

51774a81beb3
docker commit 51774a81beb3 learn/tutorial

Run the Image with Port Mappings

docker run -d -p 22 -p 80:8080 learn/tutorial /usr/sbin/sshd -D

This starts the container in the background, exposing SSH on a random host port (e.g., 49154) and mapping the container’s Tomcat port 8080 to host port 80.

Verify and Access the Services

docker ps

# shows the running container and port mappings ssh [email protected] -p 49154 # SSH into the container

Install Oracle JDK 7 and Tomcat 7.0.47 Inside the Container

apt-get install python-software-properties
add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install -y wget
apt-get install oracle-java7-installer
java -version
wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.47/bin/apache-tomcat-7.0.47.tar.gz
tar xvf apache-tomcat-7.0.47.tar.gz
cd apache-tomcat-7.0.47
bin/startup.sh

Tomcat runs on port 8080 inside the container; because of the -p 80:8080 mapping, it is reachable on the host’s port 80. Test with: curl http://192.168.190.131 Or open a browser and navigate to the host IP.

Conclusion

Using Docker to set up a Tomcat runtime is straightforward and demonstrates a basic PaaS scenario. Future articles will cover automated image building with Dockerfiles and deeper insights into Docker’s architecture and mechanisms.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerDevOpsLinuxTutorial
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.