Run XWiki (MySQL on Tomcat) Using Docker Swarm
Steps
To run XWiki with MySQL using Docker Swarm:
Enable Docker Swarm mode.
docker swarm init- Create the required Docker secrets.
- Create a secret for the database username used by XWiki.
- 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 -
- For Unix systems:
- Create a secret for the database password.
echo YourDBPassword | docker secret create xwiki-db-password - - Create a secret for the MySQL root password.
echo YourRootPassword | docker secret create xwiki-db-root-password -
- Create a secret for the database username used by XWiki.
- Create a stack definition file named xwiki-stack.yaml.
version: '3.7' services: web: image: "xwiki:stable-mysql-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: "mysql:9" volumes: - mysql-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: mysql-data: xwiki-data: secrets: xwiki-db-username: external: true xwiki-db-password: external: true xwiki-db-root-password: external: true Deploy the stack.
docker stack deploy -c xwiki-stack.yaml xwikiVerify that the services are running. Both services should show 1/1 under REPLICAS. This may take a few minutes.
docker service ls- 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.