You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署Drupal 10/MariaDB后首页出现NotFoundHttpException错误

Drupal 10 + Docker 安装后首页路由未找到错误排查

我通过Docker安装了Drupal 10与MariaDB,完成安装向导配置后,访问首页时出现如下错误(已开启调试模式):

The website encountered an unexpected error. Please try again later.

Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET http://localhost:8083/" in Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest() (line 128 of /opt/drupal/vendor/symfony/http-kernel/EventListener/RouterListener.php).
Drupal\Core\Routing\AccessAwareRouter->matchRequest(Object) (Line: 106)
Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object, 'kernel.request', Object)
call_user_func(Array, Object, 'kernel.request', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.request') (Line: 139)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 681)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

我的docker-compose配置文件:

version: '3'
services:
    drupal:
        image: drupal:10.0.2
        ports:
          - 8083:80
        volumes:
          - ./drupal_modules:/var/www/html/modules
          - ./drupal_profiles:/var/www/html/profiles
          - ./drupal_themes:/var/www/html/themes
          - ./drupal_sites:/var/www/html/sites
        # restart: always
    mariadb:
        image: mariadb:10.10
        volumes:
            - mariadb:/var/lib/mysql
        environment:
            TZ: "Europe/Rome"
            MYSQL_ALLOW_EMPTY_PASSWORD: "no"
            MYSQL_ROOT_PASSWORD: "rootpwd"
            MYSQL_USER: 'drupal'
            MYSQL_PASSWORD: 'drupal'
            MYSQL_DATABASE: 'drupal'
volumes:
    mariadb:
    # drupal_modules:
    # drupal_profiles:
    # drupal_themes:
    # drupal_sites:

我已成功验证MariaDB容器中的数据库及表:

> docker exec -it 348cd7dc8853 sh
# mysql -udrupal -p           
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.10.2-MariaDB-1:10.10.2+maria~ubu2204 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| drupal             |
| information_schema |
+--------------------+
2 rows in set (0.000 sec)

MariaDB [(none)]> use drupal
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [drupal]> show tables;
+------------------+
| Tables_in_drupal |
+------------------+
| batch            |
| cache_config     |
| cache_container  |
| cache_data       |
| cachetags        |
| config           |
| key_value        |
| queue            |
| sequences        |
| sessions         |
| user__roles      |
| users            |
| users_data       |
| users_field_data |
+------------------+
14 rows in set (0.001 sec)

排查与解决步骤

1. 检查数据库连接配置

进入Drupal容器,确认sites/default/settings.php中的数据库主机配置为mariadb(对应docker-compose中的服务名),配置示例:

$databases['default']['default'] = [
  'database' => 'drupal',
  'username' => 'drupal',
  'password' => 'drupal',
  'host' => 'mariadb',
  'port' => '3306',
  'driver' => 'mysql',
];

2. 清除Drupal缓存

调试模式下缓存仍可能残留,执行命令清除:

# 进入Drupal容器
docker exec -it <drupal容器ID> bash
cd /var/www/html
# 用drush清除缓存(若已安装)
drush cr
# 无drush则手动删除缓存目录
rm -rf sites/default/files/php/twig/* sites/default/files/cache/*

3. 修复挂载目录权限

本地挂载目录需赋予Drupal运行用户(www-data)读写权限:

chown -R www-data:www-data ./drupal_modules ./drupal_profiles ./drupal_themes ./drupal_sites

4. 重新完成安装流程

数据库表数量过少(缺少node、block等核心表),说明安装向导可能未完成。访问http://localhost:8083/core/install.php重新走安装流程。

5. 重建容器

停止并删除现有容器,重新构建:

docker-compose down
docker-compose up -d

内容的提问来源于stack exchange,提问作者Martyn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 08:45:46