I got error Class "MongoDB\Driver\Manager" not found under docker - laravel

I try to install laravel 9 /mongodbsite under docker , based on
FROM php:8.1.6-apache
But running the app I got error:
Class "MongoDB\Driver\Manager" not found
Searching in net I found a possible decision as “php-mongo” package is not installed
But adding php-mongo in as :
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
...
RUN apt-get install -y mongodb-org php-mongo
I got error :
E: Package 'php-mongo' has no installation candidate
I tried to use php-mongodb-all-dev, php8.1-mongodb, but got similar errors.
Which package and have I to install ?
Updated Part 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 \
But I got error :
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
Which format of the command is valid ?
Thanks in advance!

php-mongo is a PHP extension and the default PHP images for docker do not allow installing PHP extensions on then using apt-get.
You can try doing the following in your Dockerfile instead:
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
This is a more simplified approach than the official documentation.
More information on these images as well as the documentation to install extensions can be found in dockerhub
Information about docker-php-extension-installer can be found in Github

Related

Dockerfile | => ERROR [base 2/7] RUN apt-get update -y && apt-get -y --no-install-recommends install curl wget && rm -rf /var/lib/apt/lists/* [duplicate]

I'm trying to build a docker image but it throws an error and I can't seem to figure out why.
It is stuck at RUN apt-get -y update with the following error messages:
4.436 E: Release file for http://security.debian.org/debian-security/dists/buster/updates/InRelease is not valid yet (invalid for another 2d 16h 26min 22s). Updates for this repository will not be applied.
4.436 E: Release file for http://deb.debian.org/debian/dists/buster-updates/InRelease is not valid yet (invalid for another 3d 10h 28min 24s). Updates for this repository will not be applied.
executor failed running [/bin/sh -c apt-get -y update]: exit code: 100
Here's my docker file:
FROM python:3.7
# Adding trusting keys to apt for repositories
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
# Adding Google Chrome to the repositories
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
# Updating apt to see and install Google Chrome
RUN apt-get -y update
# Magic happens
RUN apt-get install -y google-chrome-stable
# Installing Unzip
RUN apt-get install -yqq unzip
# Download the Chrome Driver
RUN CHROMEDRIVER_RELEASE=$(curl http://chromedriver.storage.googleapis.com/LATEST_RELEASE) && \
echo "Chromedriver latest version: $CHROMEDRIVER_RELEASE" && \
wget --quiet "http://chromedriver.storage.googleapis.com/$CHROMEDRIVER_RELEASE/chromedriver_linux64.zip" && \
unzip chromedriver_linux64.zip && \
rm -rf chromedriver_linux64.zip && \
mv chromedriver /usr/local/bin/chromedriver && \
chmod +x /usr/local/bin/chromedriver && \
chromedriver --version
# Set display port as an environment variable
ENV DISPLAY=:99
WORKDIR /
COPY requirements.txt ./
RUN pip install --upgrade pip && pip install -r requirements.txt
COPY . .
RUN pip install -e .
What is happening here?
In my case, docker was still using the cached RUN apt update && apt upgrade command, thus not updating the package sources.
The solution was to build the docker image once with the --no-cache flag:
docker build --no-cache .
If you are using docker desktop, please check if enough resources are set in settings/preferences.
Eg. memory and disk requirement
It's answered here https://askubuntu.com/questions/1059217/getting-release-is-not-valid-yet-while-updating-ubuntu-docker-container
Correct your system clock. (in comments I also suggested checking for a mismatch between clock and your timezone too)
I get this ERROR: executor failed running [...]: exit code: 100 error message when I mistyped the name of a package.
This was in my Dockerfile:
RUN sudo apt-get update; \
sudo apt-get -y upgrade; \
sudo apt-get install -y gnupg2 wget lsb_release
instead of this:
RUN sudo apt-get update; \
sudo apt-get -y upgrade; \
sudo apt-get install -y gnupg2 wget lsb-release
(see the difference between the underscore and the dash.)
Fixing the package name solved the problem.
This happens specific to OS also.
I had same issues running MariaDB on my Windows 10.
Check for Docker Settings:
{
"registry-mirrors": [],
"insecure-registries": [],
"debug": false,
"experimental": false,
"features": {
"buildkit": true
},
"builder": {
"gc": {
"enabled": true,
"defaultKeepStorage": "20GB"
}
}
}
Remove below block, and it should work:
"features": {
"buildkit": true
},
I had this error and I think it was because I installed buildx but the version of the plugin didn't match my docker installation. Uninstalling buildx resolved the issue for me:
docker buildx uninstall
For me adding this to the Dockerfile did the job:
RUN apk add --update linux-headers;

Vendor folder not being generated despite being run in AWS CodeBuild

When loading my AWS Elastic Beanstalk test website using CodeBuild continual deployment, I get this error:
Warning: require(/var/app/current/clu/public/../vendor/autoload.php): failed to open stream: No such file or directory in /var/app/current/clu/public/index.php on line 24 Fatal error: require(): Failed opening required '/var/app/current/clu/public/../vendor/autoload.php' (include_path='.:/usr/share/pear7:/usr/share/php') in /var/app/current/clu/public/index.php on line 24
It seems like the composer files are not being generated.
However, in the CodeBuild logs, they are.
[Container] 2020/02/24 03:21:34 Running command composer install
03:21:38
Loading composer repositories with package information
03:21:38
Installing dependencies (including require-dev) from lock file
03:21:38
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
03:21:38
Package operations: 89 installs, 0 updates, 0 removals
03:21:38
- Installing doctrine/inflector (v1.3.0): Downloading (connecting...)Downloading (100%)
03:21:38
- Installing doctrine/lexer (1.1.0): Downloading (connect..
...
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
Discovered Package: [32mfacade/ignition[39m
Discovered Package: [32mfideloper/proxy[39m
Discovered Package: [32mlaravel/tinker[39m
Discovered Package: [32mnesbot/carbon[39m
Discovered Package: [32mnunomaduro/collision[39m
[32mPackage manifest generated successfully.[39m
This is my buildspec.yml code:
version: 0.2
phases:
install:
commands:
export DEBIAN_FRONTEND=noninteractive
#Install php7.1
apt-get update
apt-get install -y software-properties-common
LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
apt-get update
# Install PHP
apt-get install -y php7.2\
php7.2-ldap \
php7.2-xml \
php7.2-xmlrpc \
php7.2-zip \
php7.2-mysql \
php7.2-mbstring \
php7.2-mcrypt \
php7.2-gd \
php7.2-readline \
php7.2-opcache \
php7.2-xdebug \
php7.2-dom \
php-xdebug \
php7.2-curl \
unzip
phpenmod xdebug
#Install composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php ;
php -r "unlink('composer-setup.php');" ;
mv composer.phar /usr/local/bin/composer
build:
commands:
- echo Build started on `date`
- echo Installing composer deps
- composer install
post_build:
commands:
- echo Build completed on `date`
My laravel filesystem does not have the vendor folder as I would like it to be generated via composer install.
Would greatly appreciate a hand, i've tried so many things.. cant get it to generate properly.
I've also checked via ssh and the folder is not there grrr. Its like its being generated elsewhere.
Thanks!
Adding the following to my buildspec.yml enabled the vendor file to be uploaded to the working server.
artifacts:
files:
- '**/*'
proxy:
upload-artifacts: yes
logs: yes

E: Package 'mysql-client' has no installation candidate in php-fpm image build using docker compose

Im fairly new to docker and so im trying to learn more about it using a laravel project, im following this tutorial:
https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose
Ive adjusted the Dockerfile a bit from what the tutorial has but even the tutorial file causes the same result.
FROM php:7.3-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Install dependencies
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get update && apt-get install -y mysql-client \
RUN npm install -g npm
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo pdo_mysql
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Set working directory
WORKDIR /var/www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
But i keep getting the following error when i run docker-compose up -d:
E: Package 'mysql-client' has no installation candidate
ERROR: Service 'app' failed to build: The command '/bin/sh -c curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get update && apt-get install -y mysql-client nodejs build-essential vim git curl' returned a non-zero code: 100
Am i missing something?
I expected this to work since i am running apt-get update before installing mysql-client.
Thanks.
php:7.3-fpm now use Debian 10 (Buster) as its base image and Buster ships with MariaDB, so just replace mysql-client with mariadb-client should fix it.
If you still want to use the mysql client, it's called default-mysql-client now.
php:7.2-apache triggers the error as well, but I resolve it using php:7.2.18-apache
it worked for me: sudo apt-get update && apt-get install -y git curl libmcrypt-dev default-mysql-client
or alternatively apt-cache search mysql-server
find out your servers then sudo apt-get install default-mysql-server default-mysql-server-core mariadb-server-10.6 mariadb-server-core-10.6
in my case it was the above codes

Install oracle client in docker container

I am using alpine linux as a base image, and I need to install an oracle client native library. I believe you can download from here:
https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
it looks like I have to login to download, does anyone know how to download a zip file of the client lib without login?
does anyone know how to install the client library properly in a bash script or dockerfile?
I have figure out some different way to install Oracle instant client in ubuntu Docker, it might help others
Follow these simple steps:
Download oracle instant client (.rpm file) from oracle official download center
Convert into .deb (you can use apt-get install alien ) and move somewhere in your working directory.
Now Update your Dockerfile and make build
RUN apt-get update
WORKDIR /opt
ADD ./ORACLE-INSTANT-CLIENT.deb /opt
#if libaio also required
RUN apt-get install libaio1
RUN dpkg -i oracle-instantclient.deb
Here is a working solution for the official PHP-FPM images based on Debian 10 (Buster). The following Dockerfile installs the Oracle Instant Client 18.5 (basiclite and devel) using the RPM packges and alien.
As Christopher Jones wrote the files can currently be downloaded without an Oracle account.
FROM php:7.2.32-fpm
# see https://help.ubuntu.com/community/Oracle%20Instant%20Client
RUN apt-get update && apt-get install -y --no-install-recommends alien libaio1 wget && \
wget https://download.oracle.com/otn_software/linux/instantclient/185000/oracle-instantclient18.5-basiclite-18.5.0.0.0-3.x86_64.rpm && \
wget https://download.oracle.com/otn_software/linux/instantclient/185000/oracle-instantclient18.5-devel-18.5.0.0.0-3.x86_64.rpm && \
alien -i oracle-instantclient18.5-basiclite-18.5.0.0.0-3.x86_64.rpm && \
alien -i oracle-instantclient18.5-devel-18.5.0.0.0-3.x86_64.rpm
ENV LD_LIBRARY_PATH="/usr/lib/oracle/18.5/client64/lib:${LD_LIBRARY_PATH}"
If you want to download oracle at runtime then you can run the below commands
FROM ruby:3.0
ENV LD_LIBRARY_PATH=/opt/oracle/instantclient_21_4
RUN apt-get update && \
apt-get install -y libpq-dev zlib1g-dev build-essential shared-mime-info libaio1 libaio-dev unzip wget --no-install-recommends && \
wget https://download.oracle.com/otn_software/linux/instantclient/214000/instantclient-sdk-linux.x64-21.4.0.0.0dbru.zip && \
wget https://download.oracle.com/otn_software/linux/instantclient/214000/instantclient-sqlplus-linux.x64-21.4.0.0.0dbru.zip && \
wget https://download.oracle.com/otn_software/linux/instantclient/214000/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip && \
mkdir -p /opt/oracle && \
cp instantclient-* /opt/oracle/ && \
cd /opt/oracle/ && \
unzip instantclient-basic-linux.x64-21.4.0.0.0dbru.zip && \
unzip instantclient-sdk-linux.x64-21.4.0.0.0dbru.zip && \
unzip instantclient-sqlplus-linux.x64-21.4.0.0.0dbru.zip && \
rm -rf /var/lib/apt/lists/* instantclient-basic-linux.x64-21.4.0.0.0dbru.zip instantclient-sdk-linux.x64-21.4.0.0.0dbru.zip instantclient-sqlplus-linux.x64-21.4.0.0.0dbru.zip && \
apt -y clean && \
apt -y remove wget unzip && \
apt -y autoremove && \
rm -rf /var/cache/apt
You can download the specific version of instantclient by specifying the version above
These two packages are require for ruby-oci if you are using ruby on rails application
libaio1
libaio-dev
You don't want to use Alpine Linux, since you will need to hack it and it could become unstable. See https://stackoverflow.com/a/53291026/4799035 for more comments.
Also see https://github.com/oracle/docker-images/blob/master/OracleInstantClient/dockerfiles/19/Dockerfile which doesn't need any login.
In summary, on Oracle Linux 7:
yum -y install oracle-release-el7
yum -y install oracle-instantclient19.3-basic && rm -rf /var/cache/yum
Update: Oracle has Docker images at https://github.com/oracle/docker-images/pkgs/container/oraclelinux7-instantclient and https://github.com/oracle/docker-images/pkgs/container/oraclelinux8-instantclient which can be pulled like:
docker pull ghcr.io/oracle/oraclelinux7-instantclient:21
and
docker pull ghcr.io/oracle/oraclelinux8-instantclient:21

Pipeline Shell Script Permission Issue on .NET Build Attempt

I am trying to build an ASP.NET5 application via Bluemix Pipeline using a shell script to configure a runtime that supports .NET builds with DNVM. When building the application we need to get dependencies from Mono 4.0 (such as kestrel) but the latest Mono available via apt-get is 3.2. I tried to resolve this by adding the Mono deb repository in /etc/apt/sources.list so that an apt-get update would fetch the latest Mono package but due to a permission error we are not allowed to alter sources.list nor add or alter any files in /etc/apt/sources.list.d/*.
For example, running:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
sudo echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo -i tee /etc/apt/sources.list.d/mono-xamarin.list
Will result in:
sudo: no tty present and no askpass program specified
Not using sudo will give a permission issue and I think we have exhausted all possible workarounds such as ssh -t -t and forth.
Does anyone have any suggestions on a workaround for this or an alternative method to run a shell script where a .NET build with DNVM and all dependencies would be supported? Using another language or cf push in this case is not an option, we really want to push .NET through pipeline at any cost.
When experimenting with the pipeline I wasn't able to get it working with Mono either, but if you can get away with just the CoreCLR on Linux then you should be able to. Kestrel, for example, doesn't require Mono anymore.
This was a build script from the beta7 timeframe but it should be close to what's needed to use RC1 now:
#!/bin/bash
sudo apt-get update
sudo apt-get -y install libunwind8 gettext libssl-dev libcurl3-dev zlib1g
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
dnvm install 1.0.0-beta7 -r coreclr -a x64
cd src/dotnetstarter
dnu restore
dnu build
cd ../../test/dotnetstarter.tests
dnu restore
dnu build
dnx test
cd ../../src/dotnetstarter
dnu publish --runtime ~/.dnx/runtimes/dnx-coreclr-linux-x64.1.0.0-beta7
The app was https://github.com/IBM-Bluemix/asp.net5-helloworld and I added the dotnetstarter.tests project which I was trying to run in the pipeline (the dnx test step). The last publish step isn't required but is included to show it was working.
Thanks to opiethehokie, this is the working script:
#!/bin/bash
echo --- UPDATING DEPENDENCIES! ---
sudo apt-get update
echo --- DOWNLOADING PACKAGES! ---
sudo apt-get -y install libunwind8 gettext libssl-dev libcurl3-dev zlib1g libcurl4-openssl-dev libicu-dev uuid-dev
echo --- DOWNLOADING DNVM! ---
curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh && source ~/.dnx/dnvm/dnvm.sh
echo --- INSTALLING DNVM! ---
dnvm install 1.0.0-rc1-final -r coreclr -a x64
echo --- EXECUTING RESTORE! ---
cd /path-to-project-folder
dnu restore
echo --- EXECUTING BUILD! ---
dnu build
echo --- PUBLISH BUILD (OPTIONAL)! ---
dnu publish --runtime ~/.dnx/runtimes/dnx-coreclr-linux-x64.1.0.0-*`

Resources