我正在使用API Platform Symfony 环境的轻微修改版本。由于该环境中内置的 postgres 系统的一部分目前对我来说不起作用,因此我重新使用 sqlite 作为数据库提供程序。
在浏览器中加载我的 Symfony 应用程序的任何数据库连接页面时,我都会得到一些意料之中的结果An exception occurred in the driver: could not find driver
。这是有道理的,因为 docker compose 设置默认未配置为使用 sqlite。
令我惊讶的是,在相关机器上安装驱动程序实际上有多么困难。根据在其他一些问题/答案中看到的信息,以下是我尝试添加到 Dockerfile 中但没有成功的内容:
RUN apt update && apt upgrade -y
RUN apt-get install -y ca-certificates apt-transport-https
RUN apt-get install -y software-properties-common
RUN apt-get install -y python3-launchpadlib
RUN add-apt-repository http://archive.ubuntu.com/ubuntu noble-updates/main
RUN add-apt-repository ppa:ondrej/php
RUN apt update
RUN apt upgrade
RUN apt install -y php7.3-sqlite3
RUN rm -rf /var/lib/apt/lists/*
不幸的是,执行时会产生以下输出docker compose build --no-cache
:
=> ERROR [php frankenphp_base 9/17] RUN apt update 0.8s
------
> [php frankenphp_base 9/17] RUN apt update:
0.150
0.150 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
0.150
0.223 Hit:1 http://deb.debian.org/debian bookworm InRelease
0.225 Hit:2 http://deb.debian.org/debian bookworm-updates InRelease
0.239 Hit:3 http://deb.debian.org/debian-security bookworm-security InRelease
0.345 Ign:4 https://ppa.launchpadcontent.net/ondrej/php/ubuntu bookworm InRelease
0.372 Err:5 https://ppa.launchpadcontent.net/ondrej/php/ubuntu bookworm Release
0.372 404 Not Found [IP: 185.125.190.80 443]
0.452 Reading package lists...
0.763 E: The repository 'https://ppa.launchpadcontent.net/ondrej/php/ubuntu bookworm Release' does not have a Release file.
------
failed to solve: process "/bin/sh -c apt update" did not complete successfully: exit code: 100
有人知道安装这个难以捉摸的包(或功能等效包)的巧妙方法吗?
===
编辑:我后来才意识到我找错了方向。我的应用程序是通过symfony serve
主机系统提供的,而不是在 docker 容器内提供的。我一意识到这一点,就确认apt 包已经安装。之后,只需取消注释文件php-sqlite3
中的行,然后重新启动命令即可……瞧!一切正常!php.ini
;extension=pdo_sqlite
symfony serve