Run XWiki (MariaDB on Tomcat) Using Docker Swarm

Last modified by Vincent Massol on 2026/07/27 16:43

Steps

To run XWiki with MariaDB using Docker Swarm:

  1. Enable Docker Swarm mode.

    docker swarm init
  2. Create the required Docker secrets.
    1. Create a secret for the database username.
      • For Unix systems:
        echo ${MY_XWIKI_USER:-xwiki} | docker secret create xwiki-db-username -
      • For Windows systems:
        echo $env:MY_XWIKI_USER | docker secret create xwiki-db-username -
    2. Create a secret for the database password.
      echo YourDBPassword | docker secret create xwiki-db-password -
    3. Create a secret for the MariaDB root password.
      echo YourRootPassword | docker secret create xwiki-db-root-password -
  3. Create a stack definition file named xwiki-stack.yaml.
    version: '3.7'
    
    services:
      web:
        image: "xwiki:stable-mariadb-tomcat"
        init: true
        ports:
          - "8080:8080"
        environment:
          - DB_USER_FILE=/run/secrets/xwiki-db-username
          - DB_PASSWORD_FILE=/run/secrets/xwiki-db-password
          - DB_DATABASE=xwiki
          - DB_HOST=db
        volumes:
          - xwiki-data:/usr/local/xwiki
        secrets:
          - xwiki-db-username
          - xwiki-db-password
    
      db:
        image: "mariadb:12"
        volumes:
          - mariadb-data:/var/lib/mysql
        environment:
          - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/xwiki-db-root-password
          - MYSQL_USER_FILE=/run/secrets/xwiki-db-username
          - MYSQL_PASSWORD_FILE=/run/secrets/xwiki-db-password
          - MYSQL_DATABASE=xwiki
        command:
          - "--character-set-server=utf8mb4"
          - "--collation-server=utf8mb4_bin"
          - "--explicit-defaults-for-timestamp=1"
        secrets:
          - xwiki-db-username
          - xwiki-db-password
          - xwiki-db-root-password
    
    volumes:
      mariadb-data:
      xwiki-data:
    
    secrets:
      xwiki-db-username:
        external: true
      xwiki-db-password:
        external: true
      xwiki-db-root-password:
        external: true
  4. Deploy the stack.

    docker stack deploy -c xwiki-stack.yaml xwiki
  5. Verify that the services are running. Both services should show 1/1 under REPLICAS. This may take a few minutes.

    docker service ls
  6. Open XWiki in your browser at http://localhost:8080.

Don't forget to replace example values such as ${MY_XWIKI_USER:-xwiki}, $env:MY_XWIKI_USER, passwords, image tags, database names, and hostnames with values that match your environment.

FAQ

What if I want to generate a random password instead of choosing one?

Create the secret from a generated value instead of a literal one. Use the name of the secret you are creating in place of xwiki-db-password.

  • On Unix systems:
    tr -dc 'a-zA-Z0-9' </dev/urandom | head -c 16 | docker secret create xwiki-db-password -
  • On Windows:
    -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 16 | % {[char]$_}) | docker secret create xwiki-db-password -

Why do my secrets fail (on Windows)?

Windows CMD's echo command adds a trailing space to the value, which can cause authentication errors. You may use PowerShell instead.

Why do the examples run an init process?

XWiki starts a LibreOffice server to convert office documents, and that server leaves orphaned processes behind, for example when soffice.bin restarts. The JVM, which is the container's PID 1 by default, never reaps them, so they pile up as zombie processes for as long as the container runs. Running a small init process as PID 1 instead reaps them: pass --init to docker run, or set init: true on the service in a Compose or stack file. The docker-compose.yml files provided by the xwiki-docker repository already set it.

Related

Get Connected