### Dockerfile Build Layers Example Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Illustrates the layers created by Dockerfile instructions during the build process, starting from the base image. ```dockerfile Layer 1: FROM tomcat:9-jdk11-temurin-jammy (base image) Layer 2: apt-get update && apt-get upgrade Layer 3: apt-get install -y (packages) Layer 4: mkdir (directories) Layer 5: COPY docker-entrypoint.sh Layer 6: COPY update-web-app-docker.sh Layer 7: COPY tomcat_conf/server.xml Layer 8: ADD templates Layer 9: EXPOSE (metadata) Layer 10: ENTRYPOINT (metadata) ``` -------------------------------- ### Install System Packages Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Installs necessary packages like aapt, wget, sed, and postgresql-client, then cleans up apt cache to reduce image size. ```dockerfile RUN apt-get install -y \ aapt \ wget \ sed \ postgresql-client \ && rm -rf /var/lib/apt/lists/* ``` -------------------------------- ### Example WAR File Download with Credentials Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md This example demonstrates how to use the `wget` command with authentication credentials to download the Headwind MDM WAR file, mirroring the functionality within the entrypoint script. ```bash HMDM_URL=https://h-mdm.com/files/hmdm-5.39.2-os.war DOWNLOAD_CREDENTIALS="--user user --password pass" wget --user user --password pass https://h-mdm.com/files/hmdm-5.39.2-os.war ``` -------------------------------- ### Multi-Stage Build Example Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Demonstrates a multi-stage build to reduce the final image size by separating build-time dependencies from runtime requirements. ```dockerfile # Stage 1: Build/prepare FROM tomcat:9-jdk11-temurin-jammy as builder RUN apt-get update && apt-get install -y wget # ... preparation steps # Stage 2: Runtime FROM tomcat:9-jdk11-temurin-jammy # Copy only necessary files from builder COPY --from=builder /opt/hmdm/templates /opt/hmdm/templates # ... rest of configuration ``` -------------------------------- ### Troubleshoot Build: Package Installation Issues Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Addresses build failures during package installation, suggesting checks for correct package names and retrying with a fresh package cache. ```bash # Cause: Network issue or package not found # Solution: Check package names are correct apt-cache search postgres # Find postgres packages # Retry with fresh cache docker build --no-cache -t headwindmdm/hmdm:0.1.8 . ``` -------------------------------- ### Set Entrypoint in Dockerfile Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Specifies the executable to run when the container starts. This script performs initialization and starts the main application process. ```dockerfile ENTRYPOINT ["/docker-entrypoint.sh"] ``` -------------------------------- ### Start Headwind MDM with Docker Compose (Interactive) Source: https://github.com/h-mdm/hmdm-docker/blob/master/README.md Start Headwind MDM and its dependencies using Docker Compose in interactive mode. This is useful for tracing and fixing errors during initial setup. ```bash apt install -y docker-compose cd hmdm-docker cp .env.example .env vim .env # Replace ADMIN_EMAIL and BASE_DOMAIN to your values docker-compose up ``` -------------------------------- ### Installations in Dockerfile Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/utility-scripts.md Installs essential tools like aapt, wget, sed, and postgresql-client within the Docker image. ```dockerfile RUN apt-get install -y aapt wget sed postgresql-client ``` -------------------------------- ### Customize Database Initialization SQL Script Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/templates-reference.md Guide to customizing the database initialization SQL script by creating a custom script and mounting it at runtime or setting FORCE_RECONFIGURE. ```bash cp templates/sql/hmdm_init.en.sql custom_init.sql vim custom_init.sql docker run -v $(pwd)/custom_init.sql:/opt/hmdm/templates/sql/hmdm_init.en.sql \ headwindmdm/hmdm:0.1.8 Or set FORCE_RECONFIGURE to force regeneration before application uses it. ``` -------------------------------- ### Docker Run Port Configuration Examples Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/endpoints.md Map container ports to host ports using the 'docker run' command. Examples show configurations for HTTPS only, HTTP and HTTPS, and HTTP only. ```bash # HTTPS only (default) docker run -p 443:8443 -p 31000:31000 headwindmdm/hmdm:0.1.8 ``` ```bash # HTTP and HTTPS docker run -p 80:8080 -p 443:8443 -p 31000:31000 headwindmdm/hmdm:0.1.8 ``` ```bash # HTTP only docker run -p 80:8080 -p 31000:31000 -e PROTOCOL=http headwindmdm/hmdm:0.1.8 ``` -------------------------------- ### Generate SQL Initialization Script Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md Generates the database initialization SQL script by substituting installation language and version information into a template. It defaults to English if the installation language is not Russian. ```bash if [ ! -f "$BASE_DIR/init.sql" ] || [ "$FORCE_RECONFIGURE" = "true" ]; then cat $TEMPLATE_DIR/sql/hmdm_init.$INSTALL_LANGUAGE.sql | sed "s|_ADMIN_EMAIL_|$ADMIN_EMAIL|g; s|_HMDM_VERSION_|$CLIENT_VERSION|g; s|_HMDM_VARIANT_|$HMDM_VARIANT|g" > $BASE_DIR/init1.sql fi ``` -------------------------------- ### Start Headwind MDM with Docker Compose (Detached) Source: https://github.com/h-mdm/hmdm-docker/blob/master/README.md Start Headwind MDM and its dependencies using Docker Compose in detached (background) mode after successful initial setup. ```bash docker-compose up -d ``` -------------------------------- ### MQTT Client Connection Example Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/endpoints.md Connect to the Headwind MDM MQTT notification service using mosquitto_sub. This command subscribes to device status updates. ```bash # Connect to MQTT service mosquitto_sub -h mdm.example.com -p 31000 -t "device/+/status" ``` -------------------------------- ### Run Headwind MDM with Custom Configuration Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/configuration.md Example of running the Headwind MDM Docker container with various environment variables set for custom configuration. This includes settings for admin email, client version, shared secret, and installation language. ```bash docker run -e ADMIN_EMAIL=admin@example.com \ -e HMDM_VARIANT=os \ -e CLIENT_VERSION=6.36 \ -e SHARED_SECRET=my-secret-key-12345 \ -e INSTALL_LANGUAGE=en \ headwindmdm/hmdm:0.1.8 ``` -------------------------------- ### Set Default Installation Language Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md Sets the INSTALL_LANGUAGE variable to 'en' if it is not already set to 'ru'. This ensures a default language for the installation. ```bash if [ "$INSTALL_LANGUAGE" != "ru" ]; then INSTALL_LANGUAGE=en fi ``` -------------------------------- ### Get New WAR Path from Manifest Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/utility-scripts.md Reads the path of the new WAR file from the manifest file. This step is essential for identifying the specific update file to be installed. ```bash NEW_WAR_FILE=$(cat $MANIFEST_FILE) ``` -------------------------------- ### ROOT.xml Configuration Example Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/volumes-and-persistence.md This XML file configures Tomcat context parameters for Headwind MDM, including database connection details, application base URL, and security secrets. It is generated from a template and can be customized. ```xml ``` -------------------------------- ### Stop and Start Headwind MDM Container Source: https://github.com/h-mdm/hmdm-docker/blob/master/README.md Commands to stop and start a previously created Headwind MDM Docker container. ```bash docker stop hmdm docker start hmdm ``` -------------------------------- ### Add System Packages in Dockerfile Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Installs additional system packages required by the application. Ensure to clean up apt lists afterwards to reduce image size. ```dockerfile RUN apt-get install -y \ aapt \ wget \ sed \ postgresql-client \ curl \ git \ && rm -rf /var/lib/apt/lists/* ``` -------------------------------- ### Launch Tomcat Server Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md This command starts the Tomcat server in the foreground. This is the standard method for running Tomcat within a Docker container, allowing the container's process manager to monitor and control the Tomcat lifecycle. ```bash catalina.sh run ``` -------------------------------- ### Log4j Customization: Add File Appender Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/templates-reference.md Example of extending the Log4j configuration to include a file appender, logging messages to a specified file in addition to the console. ```xml ``` -------------------------------- ### Required Variables in Docker Compose .env File Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/configuration.md Example of a .env file for docker-compose deployments, specifying required variables for database configuration, domain, admin settings, network, and application parameters. This file serves as a central configuration source. ```bash # Database configuration SQL_BASE=hmdm SQL_USER=hmdm SQL_PASS=Ch@nGeMe # Domain and admin configuration ADMIN_EMAIL=info@example.com BASE_DOMAIN=mdm.example.com # Network configuration (optional, for NAT scenarios) LOCAL_IP= # Force reconfiguration on first start FORCE_RECONFIGURE= # Protocol selection PROTOCOL=https # Application configuration SHARED_SECRET=changeme-C3z9vi54 HMDM_VARIANT=os DOWNLOAD_CREDENTIALS= HMDM_URL=https://h-mdm.com/files/hmdm-5.39.2-os.war CLIENT_VERSION=6.36 ``` -------------------------------- ### Essential Docker Compose Commands for Headwind MDM Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md These commands manage the Headwind MDM Docker environment, including initialization, starting, stopping, viewing logs, and performing a complete reset. Use the reset command with caution as it deletes all data. ```bash # Initialize from template cp .env.example .env vim .env # Edit required variables # Start all services docker-compose up -d # View logs docker-compose logs -f hmdm # Stop services docker-compose stop # Complete reset (WARNING: deletes all data) ./remove-all.sh ``` -------------------------------- ### Create and Make Custom Script Executable Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/utility-scripts.md Demonstrates how to create a simple bash script and make it executable. ```bash #!/bin/bash echo "Custom initialization" chmod +x custom-init.sh ``` -------------------------------- ### Configuration Chain Overview Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/templates-reference.md Illustrates how different configuration files (ROOT.xml, log4j-hmdm.xml, init.sql, email templates) interact and reference each other. ```text ROOT.xml (Tomcat context) ├─→ Specifies: log4j.config =/usr/local/tomcat/work/log4j-hmdm.xml ├─→ Specifies: sql.init.script.path = /usr/local/tomcat/work/init.sql └─→ Specifies: Database connection parameters log4j-hmdm.xml (Logging) └─→ Logs application events init.sql (Database) ├─→ Creates schema ├─→ Inserts initial data with ADMIN_EMAIL └─→ References files to download emails/{LANGUAGE}/ (Notifications) └─→ Used for password recovery emails ``` -------------------------------- ### Check Certificate Files and Details Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md These commands list the certificate files in the Let's Encrypt directory and display the details of the certificate. Replace `$BASE_DOMAIN` with your actual base domain name. ```bash ls -la /etc/letsencrypt/live/$BASE_DOMAIN/ openssl x509 -in /etc/letsencrypt/live/$BASE_DOMAIN/cert.pem -text -noout ``` -------------------------------- ### Test Update Script with Manifest Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/utility-scripts.md Creates a test manifest file and then runs the web app update script. ```bash docker-compose exec hmdm bash -c \ 'echo "/usr/local/tomcat/work/files/test.war" > /usr/local/tomcat/work/files/hmdm_web_update_manifest.txt' # Run update script docker-compose exec hmdm /opt/hmdm/update-web-app-docker.sh ``` -------------------------------- ### Backup ROOT.xml Configuration Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/volumes-and-persistence.md Create a backup copy of the ROOT.xml configuration file before making modifications. This allows for easy restoration if needed. ```bash cp ./volumes/hmdm-config/ROOT.xml ./volumes/hmdm-config/ROOT.xml.backup ``` -------------------------------- ### Add Custom Configuration Parameter to context_template.xml Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/templates-reference.md Demonstrates how to add a new custom configuration parameter to the context_template.xml file and substitute its value using environment variables. ```bash vim templates/conf/context_template.xml cat $TEMPLATE_DIR/conf/context_template.xml | sed "... s|_CUSTOM_VALUE_|$CUSTOM_VALUE|g;" > ... docker run -e CUSTOM_VALUE=myvalue headwindmdm/hmdm:0.1.8 ``` -------------------------------- ### Attach to Headwind MDM Container Source: https://github.com/h-mdm/hmdm-docker/blob/master/README.md Execute commands inside the running Headwind MDM container using its ID. The container must be started before attaching. ```bash docker exec -it containerid /bin/bash ``` ```bash docker exec -it e81d47acec21 /bin/bash ``` -------------------------------- ### Call Custom Script from Entry Point Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/utility-scripts.md Shows how to execute a custom script from within the main entry point script. ```bash /opt/hmdm/custom-init.sh ``` -------------------------------- ### Example Password Recovery Email Body Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/volumes-and-persistence.md Illustrates the content of a password recovery email template, including placeholders for user-specific information and recovery links. ```text Hello, {USER_NAME} To complete your password recovery, please click the link: {RECOVERY_LINK} This link expires in 24 hours. ``` -------------------------------- ### Normal Headwind MDM Startup After Initial Deployment Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/configuration.md Shows a typical startup command for the Headwind MDM Docker container after initial deployment, where FORCE_RECONFIGURE is left unset or empty to use existing configurations and downloaded files. ```bash # Later deployments - normal startup docker run -e FORCE_RECONFIGURE= \ headwindmdm/hmdm:0.1.8 ``` -------------------------------- ### Configure SSL/TLS with Custom Certificates Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/configuration.md Use custom SSL/TLS certificates by disabling Let's Encrypt and specifying the path to your certificate files. Mount your certificate directory into the container. ```bash docker run -e PROTOCOL=https \ -e HTTPS_LETSENCRYPT=false \ -e HTTPS_CERT_PATH=/etc/ssl/certs \ -v /path/to/certs:/etc/ssl/certs \ headwindmdm/hmdm:0.1.8 ``` -------------------------------- ### Cleanup Cache Directory Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/volumes-and-persistence.md Removes the cache directory within the work volume. This action requires the application WAR file to be re-downloaded on the next container start. ```bash rm -rf ./volumes/work/cache ``` -------------------------------- ### Restart Headwind MDM Container Source: https://github.com/h-mdm/hmdm-docker/blob/master/README.md Restart the Docker container to apply software updates. Using 'restart' is crucial; 'start' and 'stop' will not trigger the update process. ```bash docker-compose restart hmdm ``` -------------------------------- ### Download Initialization Files Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md Downloads files referenced in the initialization SQL script, such as APKs and launchers. It downloads files only if they do not already exist in the target directory, allowing for interrupted download resumption. ```bash cd $BASE_DIR/files for FILE in $FILES_TO_DOWNLOAD; do FILENAME=$(basename $FILE) if [ ! -f "$BASE_DIR/files/$FILENAME" ]; then wget $FILE fi done ``` -------------------------------- ### Log4j Customization: Change Log Level to DEBUG Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/templates-reference.md Example of modifying the Log4j configuration to change the root log level from INFO to DEBUG for more verbose logging. ```xml ``` -------------------------------- ### Manual WAR Download and Manifest Creation Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/utility-scripts.md Provides commands for manually downloading a new WAR file and creating the necessary manifest file. This is an alternative to the automated update process via the web panel. ```bash # Download new WAR manually docker-compose exec hmdm wget https://h-mdm.com/files/hmdm-5.39.3-os.war \ -O /usr/local/tomcat/work/files/hmdm-5.39.3-os.war # Create manifest file docker-compose exec hmdm bash -c \ 'echo "/usr/local/tomcat/work/files/hmdm-5.39.3-os.war" > /usr/local/tomcat/work/files/hmdm_web_update_manifest.txt' ``` -------------------------------- ### Create Certificate Directory Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Create the necessary directory structure to store custom SSL certificates for HTTPS. ```bash mkdir -p ./volumes/letsencrypt/live/mdm.example.com/ ``` -------------------------------- ### Headwind MDM Service Definition Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/docker-compose-reference.md Defines the Headwind MDM service within a Docker Compose setup, specifying the image, ports, volumes, and environment variables. ```yaml hmdm: image: headwindmdm/hmdm:0.1.8 ports: #- 80:8080 - 443:8443 - 31000:31000 volumes: - ./volumes/work:/usr/local/tomcat/work - ./volumes/letsencrypt:/etc/letsencrypt - ./volumes/hmdm-config:/usr/local/tomcat/conf/Catalina/localhost - ./volumes/webapps:/usr/local/tomcat/webapps environment: SQL_HOST: postgresql SQL_USER: ${SQL_USER} SQL_BASE: ${SQL_BASE} SQL_PASS: ${SQL_PASS} BASE_DOMAIN: ${BASE_DOMAIN} LOCAL_IP: ${LOCAL_IP} PROTOCOL: ${PROTOCOL} ADMIN_EMAIL: ${ADMIN_EMAIL} SHARED_SECRET: ${SHARED_SECRET} HMDM_VARIANT: ${HMDM_VARIANT} DOWNLOAD_CREDENTIALS: ${DOWNLOAD_CREDENTIALS} HMDM_URL: ${HMDM_URL} CLIENT_VERSION: ${CLIENT_VERSION} FORCE_RECONFIGURE: ${FORCE_RECONFIGURE} ``` -------------------------------- ### Manually Apply Templates Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/templates-reference.md Executes the Docker entrypoint script within the HMDM container to re-run full initialization. Use with caution in production as it restarts Tomcat. ```bash docker-compose exec hmdm /docker-entrypoint.sh ``` -------------------------------- ### Force Headwind MDM Container Reconfiguration Source: https://github.com/h-mdm/hmdm-docker/blob/master/README.md Set this environment variable to force the container to reset its configuration to default. Unset it after initial setup to preserve custom settings. ```bash FORCE_RECONFIGURE=true ``` -------------------------------- ### List Certificate Files Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Verify that the SSL certificate files exist in the expected directory. ```bash # Check certificate files exist ls -la ./volumes/letsencrypt/live/mdm.example.com/ ``` -------------------------------- ### Extracting Download URLs from SQL Script Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/templates-reference.md Bash command to extract URLs starting with 'https://h-mdm.com' from an SQL file, typically used for identifying files to be downloaded during database initialization. ```bash grep https://h-mdm.com init1.sql | awk '{ print $4 }' | sed "s/'//g; s/)//g; s/,//g" ``` -------------------------------- ### Copy Custom Certificate Files Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/volumes-and-persistence.md These bash commands illustrate how to copy custom certificate files (certificate, private key, and full chain) into the designated Let's Encrypt volume directory. Ensure the paths to your certificate files are correct. ```bash mkdir -p ./volumes/letsencrypt/live/mdm.example.com/ cp /path/to/cert.pem ./volumes/letsencrypt/live/mdm.example.com/ cp /path/to/privkey.pem ./volumes/letsencrypt/live/mdm.example.com/ cp /path/to/fullchain.pem ./volumes/letsencrypt/live/mdm.example.com/ ``` -------------------------------- ### Configure Domain and Protocol Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/configuration.md Specify the base domain and protocol for accessing Headwind MDM. Optionally set a local IP for host file entries. ```bash docker run -e BASE_DOMAIN=mdm.company.com \ -e PROTOCOL=https \ -e LOCAL_IP=192.168.1.100 \ headwindmdm/hmdm:0.1.8 ``` -------------------------------- ### Troubleshoot Build: Space Issues Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Provides solutions for build failures due to insufficient disk space, including cleaning up unused Docker resources and increasing Docker's disk allocation. ```bash # Docker storage full docker system prune -a # Remove unused images and volumes # Increase Docker disk allocation in settings # Clean build directory docker system prune ``` -------------------------------- ### Copy Custom Certificate Files Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Copy your custom SSL certificate and private key files into the designated directory. ```bash cp /path/to/cert.pem ./volumes/letsencrypt/live/mdm.example.com/ cp /path/to/privkey.pem ./volumes/letsencrypt/live/mdm.example.com/ cp /path/to/fullchain.pem ./volumes/letsencrypt/live/mdm.example.com/ ``` -------------------------------- ### View Database Tables and Query Users Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Connect to the H-MDM PostgreSQL database, list tables, and query the admin user table. ```bash # Connect to database docker-compose exec postgresql psql -U hmdm -d hmdm # List tables \dt # Query users SELECT * FROM admin; # Exit \q ``` -------------------------------- ### Health Check Example using curl Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/endpoints.md This bash command demonstrates how to perform a basic health check on the Headwind MDM application by sending an HTTP request and checking for a specific string in the response. The -k flag is used to ignore SSL certificate validation. ```bash curl -k https://localhost:443/ 2>/dev/null | grep -q "Headwind MDM" && echo "Health OK" || echo "Health FAILED" ``` -------------------------------- ### Restore from Backup Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Stop H-MDM, remove existing volumes, extract the backup archive, and then restart the services. ```bash docker-compose down # Remove existing volumes rm -rf ./volumes/* # Extract backup tar -xzf backup-YYYYMMDD-HHMMSS.tar.gz # Start docker-compose up -d ``` -------------------------------- ### Create Directories Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Creates essential directories for Tomcat configuration and SSL certificates within the Docker image. ```dockerfile RUN mkdir -p /usr/local/tomcat/conf/Catalina/localhost RUN mkdir -p /usr/local/tomcat/ssl ``` -------------------------------- ### Backup All Volumes Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/volumes-and-persistence.md Creates a full backup of all project volumes into a timestamped directory. Stops services before backup and restarts after. ```bash #!/bin/bash BACKUP_DIR="./backups/$(date +%Y%m%d-%H%M%S)" mkdir -p "$BACKUP_DIR" # Stop services to ensure data consistency docker-compose stop # Backup all volumes tar -czf "$BACKUP_DIR/volumes.tar.gz" ./volumes/ # Restart services docker-compose up -d echo "Backup created at: $BACKUP_DIR" ``` -------------------------------- ### Verify HMDM_URL and Test Download Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Check if the HMDM_URL environment variable is set correctly and test manual download. Ensure DOWNLOAD_CREDENTIALS are set if authentication is required. ```bash # Verify URL is correct echo $HMDM_URL # Test download manually wget $HMDM_URL # Check for authentication requirements # If required, set DOWNLOAD_CREDENTIALS in .env ``` -------------------------------- ### Version Management: Pinned vs Latest Tag Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Demonstrates the correct practice of using specific version tags for pulling images in production, avoiding the unpredictable 'latest' tag. ```bash # Good (pinned version) docker pull headwindmdm/hmdm:0.1.8 # Bad (unpredictable) docker pull headwindmdm/hmdm:latest ``` -------------------------------- ### Perform Full Data Backup Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Stop the H-MDM service, create a compressed archive of the entire volumes directory, and then restart the service. ```bash # Full backup docker-compose stop tar -czf backup-$(date +%Y%m%d-%H%M%S).tar.gz ./volumes/ docker-compose start ``` -------------------------------- ### Check Tomcat Configuration and Webapps Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md These commands help in verifying the Tomcat server configuration and listing the deployed web applications. They are useful for diagnosing web server related issues. ```bash cat /usr/local/tomcat/conf/server.xml ls -la /usr/local/tomcat/webapps/ ``` -------------------------------- ### Update Configuration and Restart Application Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/INDEX.md Modify environment variables in the .env file and then restart the 'hmdm' service to apply changes. ```bash vim .env docker-compose restart hmdm ``` -------------------------------- ### Backup User Data Only Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Create a compressed archive containing only user-specific data like files, plugins, configuration, and the database. ```bash # User data only tar -czf user-data-$(date +%Y%m%d).tar.gz \ ./volumes/work/files \ ./volumes/work/plugins \ ./volumes/hmdm-config/ROOT.xml ``` -------------------------------- ### Create Working Directories Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md This snippet creates essential working directories for Headwind MDM if they do not already exist. These directories are used for caching, file storage, plugins, and logs. ```bash for DIR in cache files plugins logs; do [ -d "$BASE_DIR/$DIR" ] || mkdir "$BASE_DIR/$DIR" done ``` -------------------------------- ### Check Generated Configuration Files Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md These commands display the content of critical configuration and initialization files within the Tomcat directory. They are useful for verifying that configurations have been generated correctly. ```bash cat /usr/local/tomcat/conf/Catalina/localhost/ROOT.xml cat /usr/local/tomcat/work/init.sql cat /usr/local/tomcat/work/log4j-hmdm.xml ``` -------------------------------- ### View H-MDM Container Logs Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Display the logs for the H-MDM container to diagnose startup issues or runtime errors. ```bash # View full logs docker-compose logs hmdm ``` -------------------------------- ### Tag and Push Docker Image Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Tags a locally built image for a registry and pushes it. Requires logging into the Docker registry first. ```bash # Tag for Docker Hub docker tag headwindmdm/hmdm:0.1.8 dockerhub-user/hmdm:0.1.8 # Login docker login # Push docker push dockerhub-user/hmdm:0.1.8 ``` -------------------------------- ### Update Configuration and Restart Services Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/docker-compose-reference.md Update the application configuration by modifying the .env file and then restarting the services. The FORCE_RECONFIGURE=true environment variable ensures that the configuration changes are applied. ```bash FORCE_RECONFIGURE=true docker-compose up -d ``` -------------------------------- ### Configure Database Connection Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/configuration.md Set database connection parameters using environment variables. These are used to generate the Tomcat context configuration file. ```bash docker run -e SQL_HOST=db.example.com \ -e SQL_USER=hmdm \ -e SQL_PASS=securepass \ -e SQL_BASE=hmdm \ headwindmdm/hmdm:0.1.8 ``` -------------------------------- ### View Script Content Inside Container Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/utility-scripts.md Accesses and displays the content of the entry point and update scripts within a running container. ```bash docker-compose exec hmdm /bin/bash # Inside container: cat /docker-entrypoint.sh cat /opt/hmdm/update-web-app-docker.sh ``` -------------------------------- ### Verify Database Connectivity Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md This command checks the database connection by querying the database version. Ensure that the environment variables `$SQL_HOST`, `$SQL_USER`, and `$SQL_BASE` are correctly set. ```bash psql -h $SQL_HOST -U $SQL_USER -d $SQL_BASE -c 'SELECT version();' ``` -------------------------------- ### Copy Scripts and Templates Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Copies initialization scripts, update handlers, Tomcat configuration, and template files into the Docker image. ```dockerfile COPY docker-entrypoint.sh / COPY update-web-app-docker.sh /opt/hmdm/ COPY tomcat_conf/server.xml /usr/local/tomcat/conf/server.xml ADD templates /opt/hmdm/templates/ ``` -------------------------------- ### Resolve Certificate Generation Issues Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Address problems with Let's Encrypt certificate generation. Verify certbot logs, DNS resolution, firewall rules for port 80, and restart the certbot service if necessary. ```bash # Check certbot logs docker-compose logs certbot # Verify DNS is resolving docker-compose exec certbot nslookup mdm.example.com # Check firewall allows port 80 netstat -tlnp | grep :80 # Restart certbot manually docker-compose up certbot ``` -------------------------------- ### Backup Let's Encrypt Volume Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/volumes-and-persistence.md Create a compressed tar archive of the Let's Encrypt volume, which is critical for disaster recovery as it contains the irreplaceable private key. ```bash tar -czf letsencrypt-backup-$(date +%Y%m%d).tar.gz ./volumes/letsencrypt ``` -------------------------------- ### Customize Email Templates by Editing Local Files Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/templates-reference.md Instructions for customizing email templates by editing local files before building a Docker image or mounting custom templates at runtime. ```bash vim templates/emails/en/recovery_body.txt docker build -t headwindmdm/hmdm:custom . docker run -v $(pwd)/custom-emails:/opt/hmdm/templates/emails \ headwindmdm/hmdm:0.1.8 ``` -------------------------------- ### Troubleshoot Build: File Not Found During COPY Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Helps resolve 'File Not Found' errors during the COPY instruction in a Dockerfile by verifying file paths, existence, and the build context. ```bash # Cause: File path incorrect or missing # Solution: Verify file exists ls -la docker-entrypoint.sh ls -la templates/ # Check build context docker build --debug -t headwindmdm/hmdm:0.1.8 . ``` -------------------------------- ### Restore ROOT.xml Configuration Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/volumes-and-persistence.md Restore the ROOT.xml configuration file from a backup and restart the Headwind MDM container to apply the restored settings. ```bash cp ./volumes/hmdm-config/ROOT.xml.backup ./volumes/hmdm-config/ROOT.xml docker-compose restart hmdm ``` -------------------------------- ### Check Certbot Logs Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Review the logs generated by Certbot to troubleshoot issues with obtaining or renewing Let's Encrypt certificates. ```bash # If using Let's Encrypt, check certbot logs docker-compose logs certbot ``` -------------------------------- ### Directory Creation in Dockerfile Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/utility-scripts.md Creates necessary directories for Tomcat configuration and SSL certificates. ```dockerfile RUN mkdir -p /usr/local/tomcat/conf/Catalina/localhost RUN mkdir -p /usr/local/tomcat/ssl ``` -------------------------------- ### Verify WAR File Existence Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/utility-scripts.md Ensures that the WAR file specified in the manifest actually exists on the filesystem. If the file is not found, an error message is displayed, and the script exits. ```bash if [ ! -f $NEW_WAR_FILE ]; then echo "$NEW_WAR_FILE is not found." echo " Select 'admin - Check for updates - Get updates' in the web panel" exit 1 fi ``` -------------------------------- ### View Docker Compose Service Logs Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/docker-compose-reference.md Follows the logs for a specific service (e.g., hmdm, postgresql, certbot) in real-time. ```bash docker-compose logs -f hmdm docker-compose logs -f postgresql docker-compose logs -f certbot ``` -------------------------------- ### Enable Shell Debugging in Entry Point Script Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/utility-scripts.md Temporarily modifies the Dockerfile to add 'set -x' for debugging script execution. ```dockerfile RUN sed -i '1s/^/set -x\n/' /docker-entrypoint.sh ``` -------------------------------- ### Context Template Variables Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/templates-reference.md Table showing available context template variables, their descriptions, and default values. ```markdown | `smtp.password` | SMTP authentication password | `password` | | `smtp.from` | Sender email address | `admin@example.com` | | `device.allowed.address` | Allowed device IP networks (comma-separated) | `192.168.0.0/16,10.0.0.0/24` | | `ui.allowed.address` | Allowed UI access IP addresses | `192.168.0.0/16,10.0.0.0/24,213.11.0.3` | | `proxy.addresses` | Reverse proxy IP addresses | `192.168.1.101` | | `proxy.ip.header` | HTTP header for client IP | `X-Forwarded-For` | | `mqtt.message.delay` | MQTT message delay (ms) | `100` | ``` -------------------------------- ### Capture All Container Logs Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/utility-scripts.md Follows and redirects all logs from the 'hmdm' service to a file. ```bash docker-compose logs -f hmdm > deployment.log ``` -------------------------------- ### View Docker Compose Logs Source: https://github.com/h-mdm/hmdm-docker/blob/master/README.md View the logs of the Headwind MDM service managed by Docker Compose, following the output in real-time. ```bash docker-compose logs hmdm -f ``` -------------------------------- ### View Headwind MDM Application Logs Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/INDEX.md This command streams the logs for the 'hmdm' service in real-time. Use Ctrl+C to stop streaming. ```bash docker-compose logs -f hmdm ``` -------------------------------- ### Check Network Port Bindings Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Verify which processes are listening on common H-MDM ports (HTTP, HTTPS, database, etc.) to diagnose port conflicts. ```bash # Check port bindings netstat -tlnp | grep -E '80|443|31000|5432' ``` -------------------------------- ### Enable SMTP for Email Notifications Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Configure SMTP settings in ROOT.xml to enable email notifications. Ensure the correct host, port, and authentication details are provided. ```xml ``` -------------------------------- ### Build Docker Image Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Command to build the Docker image for Headwind MDM. Specifies the image name and tag. ```bash docker build -t headwindmdm/hmdm:0.1.8 . ``` -------------------------------- ### Test Database Connectivity from H-MDM Container Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Execute a simple SQL query from within the H-MDM container to test its connection to the PostgreSQL database. ```bash # Test connectivity from hmdm container docker-compose exec hmdm psql -h postgresql -U hmdm -d hmdm -c "SELECT 1;" ``` -------------------------------- ### Download Headwind MDM WAR File Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md This snippet downloads the Headwind MDM WAR file from a specified URL if it's not already cached or if a reconfiguration is forced. It includes error handling for download failures and supports authentication via `DOWNLOAD_CREDENTIALS`. ```bash HMDM_WAR="$(basename -- $HMDM_URL)" if [ -f "$CACHE_DIR/$HMDM_WAR" ] && [ "$FORCE_RECONFIGURE" = "true" ]; then rm -f $CACHE_DIR/$HMDM_WAR fi if [ ! -f "$CACHE_DIR/$HMDM_WAR" ]; then if ! wget $DOWNLOAD_CREDENTIALS $HMDM_URL -O $CACHE_DIR/$HMDM_WAR; then echo "Failed to retrieve $HMDM_URL!" exit 1 fi fi ``` -------------------------------- ### Build Headwind MDM Docker Image Source: https://github.com/h-mdm/hmdm-docker/blob/master/README.md Build the Docker image for Headwind MDM. Ensure to review and modify default variables in the Dockerfile before building. ```bash docker build -t headwindmdm/hmdm:0.1.8 . ``` -------------------------------- ### Build and Sign HeadwindMDM Docker Image Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/dockerfile-reference.md Build a signed version of the HeadwindMDM image. Requires Docker Content Trust to be set up. ```bash # Build and sign (requires docker content trust setup) docker build -t headwindmdm/hmdm:0.1.8-signed . docker trust sign headwindmdm/hmdm:0.1.8-signed ``` -------------------------------- ### PostgreSQL Service Configuration Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/endpoints.md This YAML snippet shows the configuration for the PostgreSQL service in docker-compose.yaml, including port mapping. ```yaml postgresql: ports: - 5432:5432 ``` -------------------------------- ### Verify Certificate Validity Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Use OpenSSL to inspect the details of your SSL certificate file and confirm its validity. ```bash # Verify certificate validity openssl x509 -in ./volumes/letsencrypt/live/mdm.example.com/cert.pem -text -noout ``` -------------------------------- ### Generate Tomcat Context Configuration Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md Generates the Tomcat context configuration XML file by substituting environment variables into a template. This file is crucial for setting up database credentials and application parameters. ```bash if [ ! -f "$TOMCAT_DIR/conf/Catalina/localhost/ROOT.xml" ] || [ "$FORCE_RECONFIGURE" = "true" ]; then cat $TEMPLATE_DIR/conf/context_template.xml | sed "s|_SQL_HOST_|$SQL_HOST|g; s|_SQL_PORT_|$SQL_PORT|g; s|_SQL_BASE_|$SQL_BASE|g; s|_SQL_USER_|$SQL_USER|g; s|_SQL_PASS_|$SQL_PASS|g; s|_PROTOCOL_|$PROTOCOL|g; s|_BASE_DOMAIN_|$BASE_DOMAIN|g; s|_SHARED_SECRET_|$SHARED_SECRET|g;" > $TOMCAT_DIR/conf/Catalina/localhost/ROOT.xml fi ``` -------------------------------- ### Check JKS Keystore Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md List the contents and details of the Java KeyStore (JKS) file used by Tomcat for SSL/TLS. ```bash # Check JKS keystore docker-compose exec hmdm keytool -list -v -keystore /usr/local/tomcat/ssl/hmdm.jks -storepass 123456 ``` -------------------------------- ### Log4j 1.x Logging Configuration Template Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/templates-reference.md XML template for configuring Log4j 1.x logging, directing output to the console (stdout). This is useful for application diagnostics within a Docker environment. ```xml ``` -------------------------------- ### Configure Local IP Resolution Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/entrypoint-script.md This script block configures the container's `/etc/hosts` file to resolve the `BASE_DOMAIN` to the `LOCAL_IP` if the `LOCAL_IP` environment variable is set. It handles cases where the entry already exists or if a reconfigure is forced. ```bash if [ ! -z "$LOCAL_IP" ]; then EXISTS=`grep $BASE_DOMAIN /etc/hosts` if [ -z "$EXISTS" ] || [ "$FORCE_RECONFIGURE" = "true" ]; then grep -v $BASE_DOMAIN /etc/hosts > /etc/hosts~ cp /etc/hosts~ /etc/hosts echo "$LOCAL_IP $BASE_DOMAIN" >> /etc/hosts rm -f /etc/hosts~ fi fi ``` -------------------------------- ### Force Headwind MDM Reconfiguration on First Deployment Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/configuration.md Demonstrates forcing a complete reconfiguration of Headwind MDM during its first deployment by setting the FORCE_RECONFIGURE environment variable to true. This ensures all configuration files are regenerated and the WAR file is re-downloaded. ```bash # First deployment - force initialization docker run -e FORCE_RECONFIGURE=true \ -e BASE_DOMAIN=mdm.example.com \ headwindmdm/hmdm:0.1.8 ``` -------------------------------- ### Incremental Backup of User Data Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/volumes-and-persistence.md Performs an incremental backup of specific user-related data, including files, plugins, emails, and configuration. ```bash #!/bin/bash BACKUP_DIR="./backups/$(date +%Y%m%d-%H%M%S)" mkdir -p "$BACKUP_DIR" # Backup only user data (not cache) tar -czf "$BACKUP_DIR/user-data.tar.gz" \ ./volumes/work/files \ ./volumes/work/plugins \ ./volumes/work/emails \ ./volumes/hmdm-config/ROOT.xml echo "User data backup: $BACKUP_DIR/user-data.tar.gz" ``` -------------------------------- ### Edit ROOT.xml Configuration Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/api-reference/volumes-and-persistence.md Modify the ROOT.xml configuration file directly on the host and then restart the Headwind MDM container to apply the changes. Avoid setting FORCE_RECONFIGURE=true after editing to prevent overwriting. ```bash vim ./volumes/hmdm-config/ROOT.xml ``` ```bash docker-compose restart hmdm ``` -------------------------------- ### Configure Headwind MDM for Plain HTTP Source: https://github.com/h-mdm/hmdm-docker/blob/master/README.md Modify docker-compose.yaml to use plain HTTP by commenting out the certbot section and uncommenting the HTTP port forwarding. Set the PROTOCOL environment variable. ```yaml # Comment out the certbot: section # Uncomment the port 80 forwarding # Set the environment variable in the .env file: PROTOCOL=http ``` -------------------------------- ### View Docker Container Logs Source: https://github.com/h-mdm/hmdm-docker/blob/master/README.md View the logs of the running Headwind MDM Docker container to monitor its status and troubleshoot issues. ```bash docker logs hmdm ``` -------------------------------- ### Check H-MDM Environment Variables Source: https://github.com/h-mdm/hmdm-docker/blob/master/_autodocs/quick-reference.md Inspect the environment variables within the H-MDM container, particularly those related to database connection strings. ```bash # Check environment variables docker-compose exec hmdm env | grep SQL_ ```