Files
TravianZ/DOCKER_README.md

6.0 KiB

TravianZ Docker Setup

This guide will help you set up TravianZ using Docker and Docker Compose for easy deployment.

Prerequisites

  • Docker Engine 20.10 or higher
  • Docker Compose 1.29 or higher
  • At least 2GB of free RAM
  • At least 5GB of free disk space

Quick Start

1. Clone the Repository

git clone https://github.com/Shadowss/TravianZ.git
cd TravianZ

2. Configure Environment Variables

Copy the example environment file and customize it if needed:

cp .env.example .env

Edit .env file to set your database credentials:

MARIADB_ROOT_PASSWORD=yourStrongRootPassword
MARIADB_DATABASE=travian
MARIADB_USER=travianz
MARIADB_PASSWORD=yourStrongPassword

3. Start the Containers

docker compose up -d

This command will:

  • Build the TravianZ web application container
  • Start a MariaDB (latest) database container
  • Start a phpMyAdmin container for database management
  • Set up a network for all containers to communicate

4. Access the Installation Wizard

Once the containers are running, open your browser and navigate to:

http://localhost:8080/install

5. Complete the Installation

During the installation wizard, use these database settings:

  • SQL Hostname: db (this is the Docker container name)
  • Port: 3306
  • Username: travianz (or the value from your .env file)
  • Password: travianzpass (or the value from your .env file)
  • DB name: travian (or the value from your .env file)
  • Prefix: s1_ (or customize as needed)
  • Type: MYSQLi

Complete the rest of the installation wizard with your preferred server settings.

Services and Ports

After starting the containers, the following services will be available:

Container Management

View Running Containers

docker compose ps

View Logs

# All containers
docker compose logs

# Specific container
docker compose logs web
docker compose logs db
docker compose logs phpmyadmin

# Follow logs in real-time
docker compose logs -f web

Stop Containers

docker compose down

Stop and Remove All Data

WARNING: This will delete all database data!

docker compose down -v

Restart Containers

docker compose restart

Rebuild Containers

If you make changes to the Dockerfile or application code:

docker compose down
docker compose up -d --build

Accessing the Containers

Access Web Container Shell

docker exec -it travianz-web bash

Access MySQL Container

docker exec -it travianz-db mysql -u root -p

Enter the root password from your .env file.

Troubleshooting

Installation Files Not Writable

If you get permission errors during installation:

docker exec -it travianz-web chown -R www-data:www-data /var/www/html
docker exec -it travianz-web chmod -R 777 /var/www/html/var

Database Connection Failed

  1. Make sure the database container is running:

docker compose ps


2. Check database logs:
```bash
docker compose logs db
  1. Verify the hostname is set to db (not localhost or 127.0.0.1)

Reset Installation

If you need to start the installation over:

  1. Stop containers:

docker compose down -v


2. Remove the installed flag:
```bash
rm -f var/installed
rm -f GameEngine/config.php
  1. Start containers again:

docker compose up -d


4. Access the installation wizard again at http://localhost:8080/install

### Port Already in Use

If port 8080 or 8081 is already in use, edit `docker compose` configuration (`docker-compose.yml`) and change the ports:

```yaml
services:
web:
 ports:
   - "9080:80"  # Change 8080 to any available port
phpmyadmin:
 ports:
   - "9081:80"  # Change 8081 to any available port

Backup and Restore

Backup Database

docker exec travianz-db mariadb-dump -u root -p travian > backup_$(date +%Y%m%d).sql

Restore Database

docker exec -i travianz-db mariadb -u root -p travian < backup_20231125.sql

Backup Application Files

tar -czf travianz_backup_$(date +%Y%m%d).tar.gz \
  --exclude='./var/db' \
  --exclude='./.git' \
  .

Production Deployment

For production environments, consider the following:

  1. Use Strong Passwords: Change all default passwords in .env

  2. Use SSL/TLS: Set up a reverse proxy (nginx/traefik) with Let's Encrypt

  3. Limit Database Access: Remove the database port exposure in the docker compose configuration (docker-compose.yml)

  4. Regular Backups: Set up automated backup scripts

  5. Resource Limits: Add resource constraints to containers:

services:
  web:
    deploy:
      resources:
        limits:
          cpus: '1.0'
          memory: 1G
  1. Monitoring: Consider adding monitoring tools like Prometheus and Grafana

Performance Optimization

MariaDB Tuning

Edit docker-compose.yml to add MariaDB configuration:

services:
  db:
    command: >
      --sql_mode=""
      --max_connections=200
      --innodb_buffer_pool_size=512M
      --query_cache_size=32M
      --query_cache_limit=2M

PHP Tuning

Create a custom PHP configuration file php-custom.ini:

memory_limit = 256M
upload_max_filesize = 20M
post_max_size = 20M
max_execution_time = 300

Then mount it in docker-compose.yml:

services:
  web:
    volumes:
      - ./php-custom.ini:/usr/local/etc/php/conf.d/custom.ini

Updates

To update TravianZ to the latest version:

git pull origin main
docker compose down
docker compose up -d --build

Support

For issues and questions:

License

TravianZ Project - See LICENSE file for details