Run XWiki (PostgreSQL on Tomcat) Using Docker Swarm
Steps
To run XWiki with PostgreSQL using Docker Swarm:
Enable Docker Swarm mode.
docker swarm init- Create the required Docker secrets.
- 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 -
- For Unix systems:
- Create a secret for the database password.
echo YourDBPassword | docker secret create xwiki-db-password -
- Create a secret for the database username.
- Create a stack definition file named xwiki-stack.yaml.
version: '3.7' services: web: image: "xwiki:stable-postgres-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: "postgres:18" volumes: - postgres-data:/var/lib/postgresql environment: - POSTGRES_USER_FILE=/run/secrets/xwiki-db-username - POSTGRES_PASSWORD_FILE=/run/secrets/xwiki-db-password - POSTGRES_DB=xwiki - POSTGRES_INITDB_ARGS=--encoding=UTF8 --locale-provider=builtin --locale=C.UTF-8 secrets: - xwiki-db-username - xwiki-db-password volumes: postgres-data: xwiki-data: secrets: xwiki-db-username: external: true xwiki-db-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.