I'm having issues trying to install and enable the PHP soap extension. I'm running the base image php:7.2-fpm-alpine3.6 inside a Docker container that has instructions like below in the Dockerfile. It's unclear to me how extensions are installed on Alpine. It seems to use docker-php-ext-install from what I can infer.
Dockerfile (I adopted this from somewhere):
RUN apk --no-cache add \
freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev \
wget \
git \
nginx \
ca-certificates \
supervisor \
bash \
nano \
&& docker-php-ext-install \
mysqli \
pdo_mysql \
opcache \
...
So, I tried
docker-php-ext-install soap
which told me configure: error: xml2-config not found. Please check your libxml2 installation. I tried a bunch of stuff, but
apk add --no-cache libxml2-dev
seemed to do something. I followed this again with docker-php-ext-install soap, which outputted
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la modules/* libs/*
At this point, I did not run make test, as it's unclear where I'm suppose to go find this Makefile. I searched under /usr/local/lib/php/extensions/no-debug-non-zts-20170718/, and soap.so was already there. Furthermore, my commands already enabled it for PHP-FPM. php -i showed /usr/local/etc/php/conf.d/docker-php-ext-soap.ini,.
I'm not entirely sure what I did. Is this (docker-php-ext-install) how you install extensions on this OS?
The PHP SOAP extension requires the PHP XML extension, as documented here: http://php.net/manual/en/soap.requirements.php
I expect you need to install that first.
Presumably docker-php-ext-install xml.
You shouldn't need to compile the XML library yourself as it will be part of the extension.
The solution is:
RUN set -ex && apk --no-cache add libxml2-dev
RUN docker-php-ext-install soap
You can add a utility to your image using this package
Example:
FROM php:7.2-cli
ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/
RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
install-php-extensions gd xdebug
If you want, you can remove the last line and enter the container to play around with adding packages.
docker exec -it <container_id> bash # (swap bash for sh if using alpine)
Then you can just type install-php-extensions <ext>
Not every alpine distribution contains docker-php-ext commands etc, and I don't know how to add them easily, it did not look simple at all to me.
Anyway, any php extension can be easily installed by issuing this alpine install command
to find any php extension
apk search -v 'php' |grep ldap
result
phpldapadmin-1.2.3-r4 - Web front-end for managing OpenLDAP
php7-ldap-7.2.22-r0 - PHP7 extension: LDAP
php5-ldap-5.6.40-r0 - ldap extension for PHP
to further install the extension, one must supply its name in a form without the suffix version part , eg. without -7.2.22-r0 in php7-ldap-7.2.22-r0 so it's php7-ldap
like this
apk install php7-ldap
Related
In order to resolve an issue, I am now trying install the mysql pdo via
docker-php-ext-install
as pointed out in the README of the php image.
Yet my call fails stating:
Libraries have been installed in:
/usr/src/php/ext/mysqli/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20131226/
Installing header files: /usr/local/include/php/
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la modules/* libs/*
+ cd /usr/src/php/ext/mysqlnd
+ phpize
Cannot find config.m4.
Make sure that you run '/usr/local/bin/phpize' in the top level source directory of the module
ERROR: Service 'phlaconapp' failed to build: The command '/bin/sh -c docker-php-ext-install mysqli mysqlnd pdo pdo_mysql zip' returned a non-zero code: 1
This is my docker-compose.yml:
phlaconapp:
hostname: phaclonapp
dockerfile: Dockerfile
build: ./
ports:
- "1080:80"
- "1043:433"
environment:
TERM: xterm-color
ENVIRONMENT: dev
volumes:
- ./:/var/www/html/
links:
- mysql
mysql:
image: mysql:5.6
volumes:
- ./docker/mysql.d:/etc/mysql/conf.d
ports: ["3306:3306"]
environment:
MYSQL_ROOT_PASSWORD: 'root'
This is my Dockerfile:
FROM php:5.6-apache
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php -r "if (hash_file('SHA384', 'composer-setup.php') === '070854512ef404f16bac87071a6db9fd9721da1684cd4589b1196c3faf71b9a2682e2311b36a5079825e155ac7ce150d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');"
RUN apt-get update && \
apt-get install vim git -y
RUN docker-php-ext-install mysqli mysqlnd pdo pdo_mysql zip
RUN cd / && \
git clone --depth=1 git://github.com/phalcon/cphalcon.git && \
cd cphalcon/build && \
./install
RUN echo "extension=phalcon.so" > /usr/local/etc/php/conf.d/phalcon.ini
RUN a2enmod rewrite
and running docker-compose build won't finish.
I had the same problem a while ago. I started a container and typed the ext-install command into this container. Once I found all the dependencies, I wrote them into the Dockerfile.
Example:
RUN apt-get update && apt-get install -y \
libmcrypt-dev \
&& docker-php-ext-install -j$(nproc) mcrypt
There is a dependency that libmcrypt-dev needed before you can run docker-php-ext-install mcrypt
I've checked my older Dockerfiles and found something which might help you
FROM php:5.6-apache
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
libicu-dev \
libxml2-dev \
vim \
wget \
unzip \
git \
&& docker-php-ext-install -j$(nproc) iconv intl xml soap mcrypt opcache pdo pdo_mysql mysqli mbstring \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
RUN a2enmod rewrite && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
# Create symlink for default conf
RUN ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
RUN docker-php-ext-install mbstring pdo pdo_mysql \
That code can do install any extension you want in this case mysql pdp driver but the Dockerfile should have base of FROM php:7.1.8-apache
The 2019 way and probably the 2020 way of installing memcached to your Docker PHP container is the way described on https://hub.docker.com/_/php
FROM php:latest
RUN pecl install memcached \
&& docker-php-ext-enable memcached
FROM php:5.6-cli
RUN apt-get update && apt-get install -y libmemcached-dev zlib1g-dev \
&& pecl install memcached-2.2.0 \
&& docker-php-ext-enable memcached
Seems to be a bug in phpize (https://bugs.php.net/bug.php?id=53571).
I added the following to docker-php-ext-configure:
/usr/local/bin # diff -u docker-php-ext-configure.bak docker-php-ext-configure
--- docker-php-ext-configure.bak
+++ docker-php-ext-configure
## -54,5 +54,6 ##
set -x
cd "$ext"
+[[ ! -f "config.m4" && -f "config0.m4" ]] && mv config0.m4 config.m4
phpize
./configure "$#"
Alternatively, you can use this excellent helper to install the needed libs automatically for you.
https://github.com/mlocati/docker-php-extension-installer
You only need to list the extensions you want like this:
FROM php:8.2-fpm-alpine
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 mysqli mysqlnd pdo pdo_mysql zip
Take a look at its GitHub page to see all options available to use.
I am trying to install OCI8 extension on my Alpine Linux Docker environment. Although there are several places saying it won't work, there are some which say it actually does. I have a 3.4 version and for corporate reasons it is staying like that for now.
I have done this within my Docker conf:
# Install Oracle Client and build OCI8 (Oracel Command Interface 8 - PHP extension)
USER root
ENV LD_LIBRARY_PATH=/usr/local/instantclient
ENV ORACLE_HOME=/usr/local/instantclient
RUN apk update && apk upgrade
RUN apk add musl-dev libaio autoconf && apk add --update make
## Unzip Instant Client v12
RUN pecl channel-update pecl.php.net
COPY instantclient_12_2.zip /var/www/html/instantclient_12_2.zip
RUN unzip -d /usr/local/ /var/www/html/instantclient_12_2.zip
RUN ln -s /usr/local/instantclient_12_2 /${ORACLE_HOME} && \
ln -s /${ORACLE_HOME}/libclntsh.so.* /${ORACLE_HOME}/libclntsh.so && \
ln -s /${ORACLE_HOME}/libocci.so.* /${ORACLE_HOME}/libocci.so && \
ln -s /${ORACLE_HOME}/lib* /usr/lib && \
ln -s /${ORACLE_HOME}/sqlplus /usr/bin/sqlplus &&\
ln -s /usr/lib/libnsl.so.2.0.0 /usr/lib/libnsl.so.1
RUN apk add gcc; exit 0 # This has a history of failing sometimes
RUN echo "instantclient,/usr/local/instantclient" | pecl install oci8 &&\
echo 'extension=oci8.so' > /usr/local/etc/php/conf.d/30-oci8.ini &&\
rm -rf /tmp/*.zip /var/cache/apk/* /tmp/pear/
Now the build passes, and it looks okay, however when I do a php -v I am getting the following:
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/extensions/no-debug-non-zts-20160303/oci8.so' -
Error loading shared library libnsl.so.1: No such file or directory
(needed by /usr/local/instantclient/libclntsh.so.12.1) in Unknown on
line 0
PHP version is 7.1.12.
What I've tried is doing apk add libnsl but this returns me this error:
ERROR: unsatisfiable constraints: so:libtirpc.so.3 (missing):
So I tried also adding apk add libtirpc-dev (the 'plain' libtirpc isn't available for my version or something), but that changed nothing.
Any clues?
I share my version of docker that I made to work with the latest version of alpine and instantclient basiclite. The size of the docker image is 124 mb.
I share my github where you can download it
Docker + alpine + Instantclient Basiclite
Or you can see below the content of the dockerfile
FROM alpine:latest
# Install Instantclient Basic Light Oracle and Dependencies
RUN apk --no-cache add libaio libnsl libc6-compat curl && \
cd /tmp && \
curl -o instantclient-basiclite.zip https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip -SL && \
unzip instantclient-basiclite.zip && \
mv instantclient*/ /usr/lib/instantclient && \
rm instantclient-basiclite.zip && \
ln -s /usr/lib/instantclient/libclntsh.so.19.1 /usr/lib/libclntsh.so && \
ln -s /usr/lib/instantclient/libocci.so.19.1 /usr/lib/libocci.so && \
ln -s /usr/lib/instantclient/libociicus.so /usr/lib/libociicus.so && \
ln -s /usr/lib/instantclient/libnnz19.so /usr/lib/libnnz19.so && \
ln -s /usr/lib/libnsl.so.2 /usr/lib/libnsl.so.1 && \
ln -s /lib/libc.so.6 /usr/lib/libresolv.so.2 && \
ln -s /lib64/ld-linux-x86-64.so.2 /usr/lib/ld-linux-x86-64.so.2
ENV ORACLE_BASE /usr/lib/instantclient
ENV LD_LIBRARY_PATH /usr/lib/instantclient
ENV TNS_ADMIN /usr/lib/instantclient
ENV ORACLE_HOME /usr/lib/instantclient
I might be late to answer this. I got the same problem of having a alpine base image and add oracle client to that. So i came up with this solution -
https://github.com/Shrinidhikulkarni7/OracleClient_Alpine
Here is the Dockerfile, but you would also need the shell script in it for it to work.
FROM alpine:latest
ENV LD_LIBRARY_PATH=/lib
RUN wget https://download.oracle.com/otn_software/linux/instantclient/193000/instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
unzip instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
cp -r instantclient_19_3/* /lib && \
rm -rf instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
apk add libaio
ADD script.sh /root/script.sh
RUN /root/script.sh
Over here I'm directly downloading the oracle client inside image, setting the path, adding packages and finally using the shell script for creating symbolic link.
I'd recommend using an operating system supported by Oracle, thus avoiding the headache of hacking Alpine and the uncertainty that it won't fall over at a critical time. And thus giving you some confidence your business won't be negatively impacted. Try https://github.com/oracle/docker-images/tree/master/OracleInstantClient
Other comments
Don't set ORACLE_HOME when using Instant Client. That variable is
for full software installs.
Use ldconfig to set the system library path, see
the Instant Client installation instructions e.g. here.
Use Instant Client 19, which can connect to the same DB versions that 12.2 can. (19 is really the renamed terminal 12.2 release in the new versioning system)
Using Oracle Linux Docker images has the advantage that it will download and install the 19 Instant Client without you having to manually do the download.
See this blog for info about the 'slim' Oracle Linux container it uses.
Here is the Dockerfile For Golang With ORACLE-CLIENT
FROM golang:alpine
RUN apk update
ENV CLIENT_FILENAME instantclient-basic-linux.x64-12.1.0.1.0.zip
WORKDIR /opt/oracle/lib
ADD https://github.com/bumpx/oracle-instantclient/raw/master/${CLIENT_FILENAME} .
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
apk add --update libaio libnsl && \
ln -s /usr/lib/libnsl.so.2 /usr/lib/libnsl.so.1
RUN LIBS="*/libociei.so */libons.so */libnnz12.so */libclntshcore.so.12.1 */libclntsh.so.12.1" && \
unzip ${CLIENT_FILENAME} ${LIBS} && \
for lib in ${LIBS}; do mv ${lib} /usr/lib; done && \
ln -s /usr/lib/libclntsh.so.12.1 /usr/lib/libclntsh.so && \
rm ${CLIENT_FILENAME}
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN apk add git
RUN apk add libc-dev
RUN apk add gcc
RUN go mod tidy
RUN go build -o main .
CMD ["/app/main"]
I was just tackling a similar problem to this using the Godror Golang Driver for Oracle. I was never able to solve this on using an Alpine image. The problem eventually came that libint.sh, would never fully install to be recognized by the system. Even changing the docker file to using the Glibc library.
How i eventually fixed the issue was to use the images from Oracle itself. The full version not the slim images that can be seen here: https://github.com/oracle/docker-images/tree/master/OracleLinuxDevelopers
you then have to install golang and then your Instant client and Oracle dependencies if you need it.
FROM oraclelinux:7 as builder
RUN yum install -y oracle-golang-release-el7 && \
yum install -y git && \
yum install -y golang unzip
COPY . /app
RUN go version
WORKDIR /app
{Your Docker Specific Commands Here}
{Insert Build Specific Environment Variables here}
#Oracle Specific Environment Variables
{Insert Oracle Env Variables here}
WORKDIR /root/
#Install oracle dependencies
RUN yum install -y wget unzip libaio && \
rm -rf /var/cache/yum
#install Oracle Instant Client
RUN wget https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-basic-linux.x64-19.9.0.0.0dbru.zip -O /tmp/instantclient.zip && \
unzip /tmp/instantclient.zip -d /usr/lib/instantclient && \
rm /tmp/instantclient.zip
#Install Oracle SDK
RUN wget https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-sdk-linux.x64-19.9.0.0.0dbru.zip -O /tmp/instantclient-sdk-linux.x64-19.9.0.0.0.zip && \
unzip /tmp/instantclient-sdk-linux.x64-19.9.0.0.0.zip -d /usr/lib/ && \
rm /tmp/instantclient-sdk-linux.x64-19.9.0.0.0.zip
#Install Oracle Tools through SQLPlus
RUN wget https://download.oracle.com/otn_software/linux/instantclient/199000/instantclient-sqlplus-linux.x64-19.9.0.0.0dbru.zip -O /tmp/instantclient-sqlplus-linux.x64-19.9.0.0.0.zip && \
unzip /tmp/instantclient-sqlplus-linux.x64-19.9.0.0.0.zip -d /usr/lib/ && \
rm /tmp/instantclient-sqlplus-linux.x64-19.9.0.0.0.zip
WORKDIR /app
COPY --from=builder /app/cmd/svr .
EXPOSE 8000
CMD ["./app"]
Again this is how i solved the problem for a Golang API. There may be others that solved the Alpine issue but i was never able to get it to work, even using older version of the Oracle Instant Client.
Try this Docker file. Start from the basic alpine linux image and add the required packages.
FROM alpine:3.13
WORKDIR /project
RUN wget https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-basiclite-linux.x64-21.1.0.0.0.zip -qO- | busybox unzip -q - && \
wget https://download.oracle.com/otn_software/linux/instantclient/211000/instantclient-sqlplus-linux.x64-21.1.0.0.0.zip -qO- | busybox unzip -q - && \
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.33-r0/glibc-2.33-r0.apk -q
RUN apk add --allow-untrusted libaio glibc-2.33-r0.apk
RUN cd instantclient_21_1 && cp /usr/lib/libaio.so.1 /lib/libc.musl-x86_64.so.1 . && chmod +x sqlplus
ENV LD_LIBRARY_PATH=/project/instantclient_21_1
I would appreciate any help I can get with following issue.
I've set up Symfony Messenger to use AMQP and RabbitMQ. I can dispatch message and make use of AMQPConnection within my project.
But when I try to consume the message I get following:
$ php bin/console messenger:consume-messages amqp
Attempted to load class "AMQPConnection" from the global namespace.
Did you forget a "use" statement for "PhpAmqpLib\Connection\AMQPConnection"?
The console command calls a method within AmqpFactory.php
public function createConnection(array $credentials): \AMQPConnection
{
return new \AMQPConnection($credentials);
}
So when I run the project from the browser, everything works fine. I can use AMQPConnection and all. But when running from terminal, it cannot find the AMQPConnection class.
From within my composer.json I also have the amqplib installed
"php-amqplib/php-amqplib": "^2.7",
I use Docker and the Dockerfile contains:
FROM php:7-apache
RUN usermod -u 1000 www-data &&\
a2dissite 000-default &&\
apt-get update &&\
apt-get install -y \
zlib1g-dev \
libicu-dev \
g++ \
libfreetype6-dev \
libssh-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
librabbitmq-dev \
libpng-dev &&\
docker-php-ext-configure intl &&\
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ &&\
docker-php-ext-install -j$(nproc) gd pdo_mysql intl opcache zip pcntl exif bcmath sockets &&\
a2enmod rewrite
RUN pecl install amqp \
&& docker-php-ext-enable amqp
COPY docker/apache2.conf /etc/apache2/apache2.conf
WORKDIR /var/www/project
UPDATE!
I've printed the phpinfo() and when dispatching the message I have version 7.2.8 and when executing the terminal command I have 7.2.7. So terminal is not using the Docker instance of PHP when executing the command.
Solved this, finally. I had no idea I had to go via Docker to run this command. This worked for me:
docker exec -ti container_name sh -c "cd /var/www/project/ && php bin/console messenger:consume-messages amqp"
When using Docker, Symfony commands needs to be executed inside needed container.
The problem come from trying to execute php from the local host:
$ php bin/console messenger:consume-messages amqp
whereas the local host does not have the necessary dependencies, RabbitMQ in this case.
Instead the command should be run using the right container:
$ docker exec -ti container_name sh -c "cd /var/www/project/ && php bin/console messenger:consume-messages amqp"
container_name being the name of the container having the RabbitMQ dependencies.
You are missing package librabbitmq4 in your Docker container. Add RUN apt-get update --fix-missing && apt-get update && apt-get install php-amqp to your Dockerfile and rebuild the image.
I've built a custom Docker image based off an official PHP FPM image php:7.0.14-fpm-alpine
I wanted to keep the size of the image small, so I went for the official alpine PHP-FPM version as it weighs only 27 MB.
I installed only few additional packages through my Dockerfile, and the image grew in size to as much as 277.5 MB. Here is my Dockerfile:
FROM php:7.0.14-fpm-alpine
COPY ./config/www-pool.conf /usr/local/etc/php-fpm.d/www.conf
COPY ./scripts/download-composer.sh /root/download-composer.sh
WORKDIR /root
RUN chmod +x download-composer.sh \
&& ./download-composer.sh \
&& mv composer.phar /usr/local/bin/composer
RUN ["mkdir", "/var/log/php-fpm"]
RUN apk --update add \
autoconf g++ make \
openssl-dev \
libxml2-dev
RUN pecl install \
xdebug \
mongodb
RUN docker-php-ext-enable \
xdebug.so \
mongodb.so
RUN docker-php-ext-install \
pdo_mysql \
soap
RUN addgroup sudo
RUN adduser -S luqo33 -G sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
277.5 MB is a ten-fold increase in size compared to the base image. Apart from Composer, all I needed were several PHP extensions:
mongodb
xdebug
pdo
soap
I'm not sure what contributed the most to increasing the size of my image so much. I suspect that it might be due to the dev dependencies that needed to be installed in order to successfully run pecl (openssl-dev, libxml2-dev), and that might have installed their own tree of dependencies.
Could you please advise on how I can reduce the size of my custom PHP-FPM image and still keep the necessary extensions?
I built the initial part of your image two different ways to test this. A common answer to this question is that the package index takes up extra space. In the case of Alpine Linux (using APK), you can clean up the package index like this:
rm -rf /var/cache/apk/*
However, I built the first part of the image both with and without that cleanup. It made hardly any difference (0.8 MB).
FROM php:7.0.14-fpm-alpine
WORKDIR /root
RUN ["mkdir", "/var/log/php-fpm"]
RUN apk --update add \
autoconf g++ make \
openssl-dev \
libxml2-dev \
&& rm -rf /var/cache/apk/*
Whether the cleanup command is present or not, the image weighs in at 267MB.
REPOSITORY TAG IMAGE ID CREATED SIZE
php-fpm-alpine-test2 latest b87f5e2d629d 23 seconds ago 267.1 MB
php-fpm-alpine-test1 latest 8ff7df8bebea 6 minutes ago 267.9 MB
The space used is simply the packages you're installing.
Step 4 : RUN apk --update add autoconf g++ make openssl-dev libxml2-dev && rm -rf /var/cache/apk/*
---> Running in 037a929d9e6a
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz
(1/23) Installing m4 (1.4.17-r1)
(2/23) Installing perl (5.22.2-r0)
(3/23) Installing autoconf (2.69-r0)
(4/23) Installing libgcc (5.3.0-r0)
(5/23) Installing libstdc++ (5.3.0-r0)
(6/23) Installing binutils-libs (2.26-r0)
(7/23) Installing binutils (2.26-r0)
(8/23) Installing gmp (6.1.0-r0)
(9/23) Installing isl (0.14.1-r0)
(10/23) Installing libgomp (5.3.0-r0)
(11/23) Installing libatomic (5.3.0-r0)
(12/23) Installing pkgconf (0.9.12-r0)
(13/23) Installing pkgconfig (0.25-r1)
(14/23) Installing mpfr3 (3.1.2-r0)
(15/23) Installing mpc1 (1.0.3-r0)
(16/23) Installing gcc (5.3.0-r0)
(17/23) Installing musl-dev (1.1.14-r14)
(18/23) Installing libc-dev (0.7-r0)
(19/23) Installing g++ (5.3.0-r0)
(20/23) Installing zlib-dev (1.2.8-r2)
(21/23) Installing libxml2-dev (2.9.4-r0)
(22/23) Installing make (4.1-r1)
(23/23) Installing openssl-dev (1.0.2j-r0)
Executing busybox-1.24.2-r11.trigger
OK: 220 MiB in 48 packages
As you can see from the summary at the end of this installation, apk has installed 220 MiB of new content.
My best advice would be to run all of your installation and then you can try to remove some of the packages that are only needed for build, not at run-time. For instance you may not need some of the dev packages anymore, or the compiler, automake, etc.
However, you have to keep in mind that each RUN command makes a new layer. To actually save space this way, you would have to run your apk command, all of your other installs, and the post-install cleanup, in a single RUN command, to make a single layer of it. Otherwise, whether you clean up or not, the earlier layers will still have the content and will still contribute to the image size.
RUN apk --update add \
autoconf g++ make \
openssl-dev \
libxml2-dev \
&& pecl install \
xdebug \
mongodb \
&& docker-php-ext-enable \
xdebug.so \
mongodb.so \
&& docker-php-ext-install \
pdo_mysql \
soap \
&& apk del autoconf g++ make openssl-dev libxml2-dev \
&& rm -rf /var/cache/apk/*
In order to resolve an issue, I am now trying install the mysql pdo via
docker-php-ext-install
as pointed out in the README of the php image.
Yet my call fails stating:
Libraries have been installed in:
/usr/src/php/ext/mysqli/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20131226/
Installing header files: /usr/local/include/php/
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la modules/* libs/*
+ cd /usr/src/php/ext/mysqlnd
+ phpize
Cannot find config.m4.
Make sure that you run '/usr/local/bin/phpize' in the top level source directory of the module
ERROR: Service 'phlaconapp' failed to build: The command '/bin/sh -c docker-php-ext-install mysqli mysqlnd pdo pdo_mysql zip' returned a non-zero code: 1
This is my docker-compose.yml:
phlaconapp:
hostname: phaclonapp
dockerfile: Dockerfile
build: ./
ports:
- "1080:80"
- "1043:433"
environment:
TERM: xterm-color
ENVIRONMENT: dev
volumes:
- ./:/var/www/html/
links:
- mysql
mysql:
image: mysql:5.6
volumes:
- ./docker/mysql.d:/etc/mysql/conf.d
ports: ["3306:3306"]
environment:
MYSQL_ROOT_PASSWORD: 'root'
This is my Dockerfile:
FROM php:5.6-apache
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php -r "if (hash_file('SHA384', 'composer-setup.php') === '070854512ef404f16bac87071a6db9fd9721da1684cd4589b1196c3faf71b9a2682e2311b36a5079825e155ac7ce150d') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');"
RUN apt-get update && \
apt-get install vim git -y
RUN docker-php-ext-install mysqli mysqlnd pdo pdo_mysql zip
RUN cd / && \
git clone --depth=1 git://github.com/phalcon/cphalcon.git && \
cd cphalcon/build && \
./install
RUN echo "extension=phalcon.so" > /usr/local/etc/php/conf.d/phalcon.ini
RUN a2enmod rewrite
and running docker-compose build won't finish.
I had the same problem a while ago. I started a container and typed the ext-install command into this container. Once I found all the dependencies, I wrote them into the Dockerfile.
Example:
RUN apt-get update && apt-get install -y \
libmcrypt-dev \
&& docker-php-ext-install -j$(nproc) mcrypt
There is a dependency that libmcrypt-dev needed before you can run docker-php-ext-install mcrypt
I've checked my older Dockerfiles and found something which might help you
FROM php:5.6-apache
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
libicu-dev \
libxml2-dev \
vim \
wget \
unzip \
git \
&& docker-php-ext-install -j$(nproc) iconv intl xml soap mcrypt opcache pdo pdo_mysql mysqli mbstring \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
RUN a2enmod rewrite && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
# Create symlink for default conf
RUN ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
RUN docker-php-ext-install mbstring pdo pdo_mysql \
That code can do install any extension you want in this case mysql pdp driver but the Dockerfile should have base of FROM php:7.1.8-apache
The 2019 way and probably the 2020 way of installing memcached to your Docker PHP container is the way described on https://hub.docker.com/_/php
FROM php:latest
RUN pecl install memcached \
&& docker-php-ext-enable memcached
FROM php:5.6-cli
RUN apt-get update && apt-get install -y libmemcached-dev zlib1g-dev \
&& pecl install memcached-2.2.0 \
&& docker-php-ext-enable memcached
Seems to be a bug in phpize (https://bugs.php.net/bug.php?id=53571).
I added the following to docker-php-ext-configure:
/usr/local/bin # diff -u docker-php-ext-configure.bak docker-php-ext-configure
--- docker-php-ext-configure.bak
+++ docker-php-ext-configure
## -54,5 +54,6 ##
set -x
cd "$ext"
+[[ ! -f "config.m4" && -f "config0.m4" ]] && mv config0.m4 config.m4
phpize
./configure "$#"
Alternatively, you can use this excellent helper to install the needed libs automatically for you.
https://github.com/mlocati/docker-php-extension-installer
You only need to list the extensions you want like this:
FROM php:8.2-fpm-alpine
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 mysqli mysqlnd pdo pdo_mysql zip
Take a look at its GitHub page to see all options available to use.