skip to Main Content

I am currently building a base image for my project. The project is using mongodb. I’ve successfully created the image but an error shows up when I try to call the endpoint which is related with SSL on libmongoc:

The SCRAM_SHA_256 authentication mechanism requires libmongoc built with ENABLE_SSL

Below are the some notable stuffs about my docker image:

  • alpine 3.8
  • php 7.2
  • nginx
  • lumen-framework 5.6.*

Below are the current implementation which has the problem, your suggestions are appreciated:

FROM alpine:3.8

RUN apk update && apk upgrade
RUN apk --no-cache add composer curl gcc git make musl-dev nginx 
    openssl openssl-dev php7 php7-ctype php7-curl php7-dev 
    php7-dom php7-fileinfo php7-fpm php7-gd php7-iconv 
    php7-imagick php7-intl php7-json php7-mbstring php7-mysqli 
    php7-opcache php7-openssl php7-pdo php7-pdo_mysql php7-pear 
    php7-redis php7-simplexml php7-tokenizer php7-xdebug 
    php7-xmlreader php7-xmlwriter php7-zip php7-zlib supervisor tzdata
RUN pecl install mongodb 
    && pecl config-set php_ini /etc/php7/php.ini 
    && echo "extension=mongodb.so" > /etc/php7/conf.d/20_mongodb.ini

Aside from above Dockerfile, I also tried to manually build the mongo-php-driver based on this article , but it doesn’t help. Both options still show me that SSL is disabled when I check with php -i | grep mongo. Do tell me if I need to include another information.

2

Answers


  1. The original post was over a year ago. But I also was trumped by this error:
    The SCRAM_SHA_256 authentication mechanism requires libmongoc built with ENABLE_SSL.

    The solutions below assume that you have a docker-compose configuration for mongodb.

    My solution was to first stop and remove the container that is implementing mongoDB … call that container workspace:

    Stack:

    • latest alpine
    • nginx
    • php7.3,
    • Laravel 8.x

    Dockerfile work for creation of mongodb extension

    RUN apk add redis gnupg openrc openssl libbsd==0.9.1-r1 && rm -rf /var/cache/apk/*
    
    RUN apk update && apk upgrade &&
        apk add --no-cache php7-pear php7-dev php7-openssl gcc musl-dev make &&
        apk add curl-dev openssl openssl-dev &&
        pecl channel-update pecl.php.net &&
        pecl install mongodb &&
        pecl config-set php_ini /etc/php7/php.ini
    
    RUN echo "extension=mongodb.so" >> /etc/php7/php.ini &&
        php --ri mongodb
    

    Build the container

    docker-compose stop workspace && docker-compose rm -f workspace && docker-compose build --no-cache workspace
    

    Bashing into the container: docker-compose exec workspace bash

    verify that MongoDB is in fact existing as a php module:

    bash-5.0# php -m | grep mongodb
    mongodb
    

    Verify SSL Enabled on libmongoc

    enter command: php --ri mongodb
    

    Response is:

    bash-5.0# php --ri mongodb
    
    mongodb <<<<<< Response means mongo is enabled.  See more below.
    
    MongoDB support => enabled
    MongoDB extension version => 1.12.0
    MongoDB extension stability => stable
    libbson bundled version => 1.20.0
    libmongoc bundled version => 1.20.0
    libmongoc SSL => enabled <<<< SSL Enabled fixes the problem.
    libmongoc SSL library => OpenSSL
    libmongoc crypto => enabled
    libmongoc crypto library => libcrypto
    libmongoc crypto system profile => disabled
    libmongoc SASL => disabled
    libmongoc ICU => disabled
    libmongoc compression => enabled
    libmongoc compression snappy => disabled
    libmongoc compression zlib => enabled
    libmongoc compression zstd => disabled
    libmongocrypt bundled version => 1.3.0
    libmongocrypt crypto => enabled
    libmongocrypt crypto library => libcrypto
    
    Directive => Local Value => Master Value
    mongodb.debug => no value => no value
    mongodb.mock_service_id => Off => Off
    
    Login or Signup to reply.
  2. Run the commands in the following order-

    wget https://github.com/mongodb/mongo-c-driver/releases/download/1.18.0/mongo-c-driver-1.18.0.tar.gz
    tar xzf mongo-c-driver-1.18.0.tar.gz
    cd mongo-c-driver-1.18.0
    mkdir cmake-build
    cd cmake-build
    cmake ..
    

    Then make sure all the downloaded modules were placed in the extension directory which is detailed in the php.ini’s phpinfo()

    Then add extension=“libmongoc.so” and #extension=“mongodb.so” to php.ini.

    Then finally remember to restart the machine or docker container in your instance.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search