Cloud Native 9 min read

How to Build a Tomcat Runtime on Docker: A Step‑by‑Step Guide

This tutorial walks through setting up Docker on an Ubuntu VM, configuring user permissions, pulling a tutorial image, installing SSH, committing the container, and finally deploying Tomcat inside the container with port mappings, providing a complete hands‑on example of container‑based PAAS.

ITPUB
ITPUB
ITPUB
How to Build a Tomcat Runtime on Docker: A Step‑by‑Step Guide

Environment

All commands are executed on a 64‑bit Ubuntu 13.10 server running inside VMware Workstation.

Install Docker

Check AUFS support and kernel version (Docker 0.7 requires Linux 3.8).

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

Verify installation with sudo docker version (client and server version 0.7.1).

Remove sudo for Docker commands

Create a dedicated docker group and add the current user (e.g., yongboy) to it, then restart the Docker daemon.

sudo groupadd docker
sudo gpasswd -a yongboy docker
sudo service docker restart

After restart, test with docker version. If it still requires sudo, reboot the host ( sudo reboot).

Run a Docker instance (Ubuntu)

Pull the official tutorial image and start a container.

docker pull learn/tutorial
docker run learn/tutorial /bin/echo hello world

Enter the container interactively:

docker run -i -t learn/tutorial /bin/bash

Install SSH server inside the container

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

# returns /usr/sbin/sshd

mkdir /var/run/sshd
passwd

# set a password (e.g., 123456) for the root user

exit

Commit the container as a new image

Identify the container ID and commit it. docker ps -l # shows container ID 51774a81beb3

docker commit 51774a81beb3 learn/tutorial

Run the image with SSH and Tomcat ports

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

Check running containers: docker ps. The SSH port is mapped to a random host port (e.g., 49154).

Connect via SSH:

ssh [email protected] -p 49154

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 the container was started with -p 80:8080, the host’s port 80 forwards to Tomcat. Verify with curl http://192.168.190.131 or a web browser.

Conclusion

Using Docker to assemble a Tomcat runtime is straightforward and demonstrates a basic PAAS scenario. Future articles will cover automated image building with Dockerfiles and deeper explanations of 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.

DeploymentContainerTomcatUbuntu
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.