diff --git a/11/mysql-tomcat/xwiki/docker-entrypoint.sh b/11/mysql-tomcat/xwiki/docker-entrypoint.sh
index 8f8685abb67724b9d16cadb18cf4ab7dc7006ce4..e8de6d1276d21d1479eae464afb7b1f246b47283 100755
--- a/11/mysql-tomcat/xwiki/docker-entrypoint.sh
+++ b/11/mysql-tomcat/xwiki/docker-entrypoint.sh
@@ -128,6 +128,11 @@ function configure() {
   safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
   safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
 
+  # Set any non-default main wiki database name in the xwiki.cfg file.
+  if [ "$DB_DATABASE" != "xwiki" ]; then
+    xwiki_set_cfg "xwiki.db" $DB_DATABASE
+  fi
+
   echo '  Generating authentication validation and encryption keys...'
   xwiki_set_cfg 'xwiki.authentication.validationKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
   xwiki_set_cfg 'xwiki.authentication.encryptionKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
diff --git a/11/postgres-tomcat/xwiki/docker-entrypoint.sh b/11/postgres-tomcat/xwiki/docker-entrypoint.sh
index 8f8685abb67724b9d16cadb18cf4ab7dc7006ce4..e8de6d1276d21d1479eae464afb7b1f246b47283 100755
--- a/11/postgres-tomcat/xwiki/docker-entrypoint.sh
+++ b/11/postgres-tomcat/xwiki/docker-entrypoint.sh
@@ -128,6 +128,11 @@ function configure() {
   safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
   safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
 
+  # Set any non-default main wiki database name in the xwiki.cfg file.
+  if [ "$DB_DATABASE" != "xwiki" ]; then
+    xwiki_set_cfg "xwiki.db" $DB_DATABASE
+  fi
+
   echo '  Generating authentication validation and encryption keys...'
   xwiki_set_cfg 'xwiki.authentication.validationKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
   xwiki_set_cfg 'xwiki.authentication.encryptionKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
diff --git a/12/mysql-tomcat/xwiki/docker-entrypoint.sh b/12/mysql-tomcat/xwiki/docker-entrypoint.sh
index 8f8685abb67724b9d16cadb18cf4ab7dc7006ce4..e8de6d1276d21d1479eae464afb7b1f246b47283 100755
--- a/12/mysql-tomcat/xwiki/docker-entrypoint.sh
+++ b/12/mysql-tomcat/xwiki/docker-entrypoint.sh
@@ -128,6 +128,11 @@ function configure() {
   safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
   safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
 
+  # Set any non-default main wiki database name in the xwiki.cfg file.
+  if [ "$DB_DATABASE" != "xwiki" ]; then
+    xwiki_set_cfg "xwiki.db" $DB_DATABASE
+  fi
+
   echo '  Generating authentication validation and encryption keys...'
   xwiki_set_cfg 'xwiki.authentication.validationKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
   xwiki_set_cfg 'xwiki.authentication.encryptionKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
diff --git a/12/postgres-tomcat/xwiki/docker-entrypoint.sh b/12/postgres-tomcat/xwiki/docker-entrypoint.sh
index 8f8685abb67724b9d16cadb18cf4ab7dc7006ce4..e8de6d1276d21d1479eae464afb7b1f246b47283 100755
--- a/12/postgres-tomcat/xwiki/docker-entrypoint.sh
+++ b/12/postgres-tomcat/xwiki/docker-entrypoint.sh
@@ -128,6 +128,11 @@ function configure() {
   safesed "replacecontainer" $DB_HOST /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
   safesed "replacedatabase" $DB_DATABASE /usr/local/tomcat/webapps/$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
 
+  # Set any non-default main wiki database name in the xwiki.cfg file.
+  if [ "$DB_DATABASE" != "xwiki" ]; then
+    xwiki_set_cfg "xwiki.db" $DB_DATABASE
+  fi
+
   echo '  Generating authentication validation and encryption keys...'
   xwiki_set_cfg 'xwiki.authentication.validationKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
   xwiki_set_cfg 'xwiki.authentication.encryptionKey' "$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
diff --git a/template/xwiki/docker-entrypoint.sh b/template/xwiki/docker-entrypoint.sh
index e40a677cb9f2c87e60dfffb17456716036d0a321..cdfdbaca75caf9f359f4b1f55ee49f947d538a6b 100755
--- a/template/xwiki/docker-entrypoint.sh
+++ b/template/xwiki/docker-entrypoint.sh
@@ -128,6 +128,11 @@ function configure() {
   safesed "replacecontainer" \$DB_HOST /usr/local/tomcat/webapps/\$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
   safesed "replacedatabase" \$DB_DATABASE /usr/local/tomcat/webapps/\$CONTEXT_PATH/WEB-INF/hibernate.cfg.xml
 
+  # Set any non-default main wiki database name in the xwiki.cfg file.
+  if [ "\$DB_DATABASE" != "xwiki" ]; then
+    xwiki_set_cfg "xwiki.db" \$DB_DATABASE
+  fi
+
   echo '  Generating authentication validation and encryption keys...'
   xwiki_set_cfg 'xwiki.authentication.validationKey' "\$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
   xwiki_set_cfg 'xwiki.authentication.encryptionKey' "\$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"