Help Center

Java + Tomcat + MySQL

Apache Tomcat is the most used servlet container in the Java ecosystem: it runs applications packaged as .war built with the Servlets and JSP API.

This Stack combines it with MySQL, and is suitable for traditional Java applications that are deployed as a .war file rather than as a standalone executable.

Services included

In addition to your application, the Stack brings up MySQL, an nginx that receives traffic on port 80, an automatic backups service and the web file manager.

Project structure

text
.
β”œβ”€β”€ app
β”‚   β”œβ”€β”€ META-INF
β”‚   β”‚   └── MANIFEST.MF
β”‚   β”œβ”€β”€ WEB-INF
β”‚   β”‚   β”œβ”€β”€ ...
β”‚   β”‚   └── web.xml
β”‚   β”œβ”€β”€ images
β”‚   β”‚   └── tomcat.gif
β”‚   β”œβ”€β”€ MANIFEST.MF
β”‚   β”œβ”€β”€ hello.jsp
β”‚   β”œβ”€β”€ index.html
β”‚   └── status.json
β”œβ”€β”€ backup
β”‚   └── backup-runner.sh
β”œβ”€β”€ nginx
β”‚   └── default.conf
β”œβ”€β”€ .env.example
β”œβ”€β”€ app.Dockerfile
└── compose.yaml

Getting started

Install the Stack and start it:

bash
docker-deploy-stack --stack java/tomcat-mysql
cd /root/stack/java/tomcat-mysql
docker compose up -d

Then replace the sample application with yours, from Git, via SFTP or from the web file manager, following how-do-i-deploy-an-application-in-a-stack.md. Your code goes in the app/ folder.

Each time you update the code, apply the changes:

bash
docker compose up -d --build

Configuration

Editable values are in the Stack’s .env file:

Variable Default Purpose
APP_PORT 80 Public port of the Stack.
APP_ENV development Application environment.
DB_NAME db Database name.
BACKUP_ENABLED 1 Automatic backups: 1 enabled, 0 disabled.
BACKUP_INTERVAL_SECONDS 86400 How many seconds between backups.
BACKUP_RETENTION_DAYS 7 How many days backups are retained.
MARIADB_VERSION 10-focal Corresponding image version.

After changing it, apply the changes with docker compose up -d.

Useful commands

bash
docker compose ps          # view the containers that are running
docker compose logs -f     # view live logs
docker compose restart     # restart the services
docker compose down        # stop and remove the containers
Guide g.0287 Β· Source version 1 Β· en