laravel 我得到错误类“MongoDB\驱动程序\管理器”未在Docker下找到

kadbb459  于 2023-02-05  发布在  Go
关注(0)|答案(1)|浏览(159)

我尝试在docker下安装laravel 9/mongodbsite,基于

FROM php:8.1.6-apache

但运行应用程序,我得到了错误:

Class "MongoDB\Driver\Manager" not found

在网上搜索,我发现一个可能的决定,因为“php-mongo”软件包没有安装
但是添加php-mongo作为:
运行重量-qO-https://www.mongodb.org/static/pgp/server-6.0.asc|apt键添加

RUN echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list

...
运行apt-获取安装-y mongodb-org php-mongo
出现错误:

E: Package 'php-mongo' has no installation candidate

我试着使用php-mongodb-all-dev,php8.1-mongodb,但是得到了类似的错误。
哪个软件包有我安装?

    • 更新第1部分:**
I modified Dockerfile.yml as :

  FROM php:8.1.6-apache

  RUN apt-get update && \
  apt-get install --assume-yes --no-install-recommends --quiet \
  curl \
  wget \
  gnupg

  RUN wget -qO  - https://www.mongodb.org/static/pgp/server-6.0.asc | apt-key add -

    RUN echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list

  ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

  RUN chmod +x /usr/local/bin/install-php-extensions \
  && install-php-extensions mongo

    RUN apt-get update && \
    apt-get install --assume-yes --no-install-recommends --quiet \

  python \
    apt-transport-https \
    libfreetype6-dev \

但我得到了错误:

docker-compose up -d --build
...

Reading package lists...
### INSTALLING REQUIRED PACKAGES ###
# Packages to be kept after installation: 
# Packages to be used only for installation: libsasl2-dev libssl-dev
debconf: delaying package configuration, since apt-utils is not installed
(Reading database ... 14467 files and directories currently installed.)
Preparing to unpack .../libssl1.1_1.1.1n-0+deb11u3_amd64.deb ...
Unpacking libssl1.1:amd64 (1.1.1n-0+deb11u3) over (1.1.1n-0+deb11u2) ...
Setting up libssl1.1:amd64 (1.1.1n-0+deb11u3) ...
Selecting previously unselected package libsasl2-dev.
(Reading database ... 14467 files and directories currently installed.)
Preparing to unpack .../libsasl2-dev_2.1.27+dfsg-2.1+deb11u1_amd64.deb ...
Unpacking libsasl2-dev (2.1.27+dfsg-2.1+deb11u1) ...
Selecting previously unselected package libssl-dev:amd64.
Preparing to unpack .../libssl-dev_1.1.1n-0+deb11u3_amd64.deb ...
Unpacking libssl-dev:amd64 (1.1.1n-0+deb11u3) ...
Setting up libsasl2-dev (2.1.27+dfsg-2.1+deb11u1) ...
Setting up libssl-dev:amd64 (1.1.1n-0+deb11u3) ...
Processing triggers for libc-bin (2.31-13+deb11u3) ...
### INSTALLING REMOTE MODULE mongo ###
WARNING: "pecl/mongo" is deprecated in favor of "channel:///mongodb"
pecl/mongo requires PHP (version >= 5.3.0, version <= 5.99.99), installed version is 8.1.6
No valid packages found
install failed
ERROR: Service 'web' failed to build: The command '/bin/sh -c chmod +x /usr/local/bin/install-php-extensions   && install-php-extensions mongo' returned a non-zero code: 1

哪种命令格式有效?
先谢了!

ffscu2ro

ffscu2ro1#

php-mongo是一个PHP扩展,docker的默认PHP映像不允许使用apt-get在其上安装PHP扩展。
您可以尝试在Dockerfile中执行以下操作:

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions \
    && install-php-extensions mongodb

这是一种比官方文档更简单的方法。关于这些映像以及安装扩展的文档的更多信息可以在dockerhub中找到
有关docker-php-extension-installer的信息可以在Github中找到

相关问题