Installing PHP sdk with Couchbase server in Docker doubles image size

Hi,
i was trying to use couchbase as my NosqlDb for my latest php project. While creating docker image i am noticing that the size of image goes high from 195MB to 522MB (after enabling couchbase server as https://developer.couchbase.com/documentation/server/current/sdk/php/start-using-sdk.html). This is adding additional time for file processing and deployment. Doesn’t look right to me please share some thoughts how i can avoid this massive size difference in docker image.
My couchbase server sits on a different server all i need is to communicate my app with db, Is there any way i can just install a light wight extension or library… ?

just FYI i am new to docker and also to couchbase… please forgive if i ask anything silly…
please also check below docker file that i am using to create image…
thanks

    FROM phpdockerio/php72-fpm:latest
    WORKDIR "/application"

    RUN apt-get update \
        && apt-get -y --no-install-recommends install  php7.2-mysql php-redis php7.2-gd php-imagick \
        && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
    	&& apt-get update \
    	&& apt-get install -y wget lsb-release \
    	RUN apt-get update \
    && apt-get -y --no-install-recommends install  php7.2-mysql php-redis php7.2-gd php-imagick \
    && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* \
	&& apt-get update \
	&& apt-get install -y wget lsb-release 
	
RUN wget http://packages.couchbase.com/releases/couchbase-release/couchbase-release-1.0-2-amd64.deb \
	&& dpkg -i couchbase-release-1.0-2-amd64.deb \
	&& rm couchbase-release-1.0-2-amd64.deb \
	&& apt-get update \
	&& apt-get install -y libcouchbase-dev build-essential php7.2-dev zlib1g-dev \
	&& pecl install pcs-1.3.3 \
	&& pecl install couchbase \

If it’s just to run an application (in say, Docker Swarm), you shouldn’t need the couchbase-release-1.0-2 package. The pecl install couchbase and dependencies such as libcouchbase are all you need. The pecl extension, intentionally, doesn’t depend on anything in the server package for this use.

Hope that helps!

1 Like

You don’t need pcs anymore. Also it seems like use installing extension from source, which means your image will include compilers, development headers etc. You can try to install binaries instead.

Try Fedora Linux, it has php couchbase module in main package repositories https://apps.fedoraproject.org/packages/php-pecl-couchbase2. If you would choose CentOS, you can use repositories from Remi Collet.

If you don’t want to install CentPS or Fedora, I would recommend you to build binaries for module in one image and deploy them in your application image, so that you won’t need all development environment there. Or even better build your own deb package for the module.

1 Like

Thanks for your reply,

i see details here https://github.com/couchbase/php-couchbase about building binaries for module, but i m quite not sure… could you please show me how to impliment that for docker ubuntu setup ?

that will be very use full for anybody using Docker couchbase php in unbutu server…

thanks i advance

The Dockerfile you’ve posted is fine for building the module (except pcs, mysql, redis, gd and imagick are not required to build couchbase library).

So once you’ve build an extension, you have to copy module to the docker image you are going to use in runtime. The only file you need is couchbase.so. In RPM-based repositories it is located at:

/usr/lib64/php-zts/modules/couchbase.so
/usr/lib64/php/modules/couchbase.so

In your case, you have to consult documentation for your distribution or docker image to find out where to look for the module.