Skip to content

Instantly share code, notes, and snippets.

@Mikulas
Last active March 11, 2022 12:34
Show Gist options
  • Save Mikulas/449746102591d636640467910eaf8aad to your computer and use it in GitHub Desktop.
Save Mikulas/449746102591d636640467910eaf8aad to your computer and use it in GitHub Desktop.
Docker image PHP 7.1 alpine with extensions
FROM php:7.1-fpm-alpine
RUN apk add --update \
autoconf \
g++ \
libtool \
make \
&& docker-php-ext-install mbstring \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install opcache \
&& apk add --update icu-dev \
&& docker-php-ext-install intl \
&& apk add --update postgresql-dev \
&& docker-php-ext-install pgsql \
&& apk del \
postgresql-libs \
libsasl \
db \
&& docker-php-ext-install sockets \
&& touch /usr/local/etc/php/bogus.ini \
&& pear config-set php_ini /usr/local/etc/php/bogus.ini \
&& pecl config-set php_ini /usr/local/etc/php/bogus.ini \
&& apk add --update \
libevent-dev \
openssl-dev \
&& pecl install event \
&& docker-php-ext-enable event \
&& mv /usr/local/etc/php/conf.d/docker-php-ext-event.ini \
/usr/local/etc/php/conf.d/docker-php-ext-zz-event.ini \
&& rm /usr/local/etc/php/bogus.ini \
&& apk del \
autoconf \
bash \
binutils \
binutils-libs \
db \
expat \
file \
g++ \
gcc \
gdbm \
gmp \
isl \
libatomic \
libbz2 \
libc-dev \
libffi \
libgcc \
libgomp \
libldap \
libltdl \
libmagic \
libsasl \
libstdc++ \
libtool \
m4 \
make \
mpc1 \
mpfr3 \
musl-dev \
perl \
pkgconf \
pkgconfig \
python \
re2c \
readline \
sqlite-libs \
zlib-dev \
&& rm -rf /tmp/* /var/cache/apk/*
# Those packages are not removed, because extensions are dynamically linked against them:
# - icu-libs
# - libpq
# - openssl-dev
# - postgresql-libs
# - libevent
# - postgresql-dev
# - libevent-dev
# - icu-dev
@Mikulas
Copy link
Author

Mikulas commented Apr 3, 2017

Docker image PHP 7.1 alpine with extensions

Final size: 161 MB
Flattening the image yields an image with 160 MB, so I don't recommend it.

Installed extensions:

  • Core
  • ctype
  • curl
  • date
  • dom
  • fileinfo
  • filter
  • ftp
  • hash
  • iconv
  • intl
  • json
  • libxml
  • mbstring
  • mysqli
  • mysqlnd
  • openssl
  • pcre
  • PDO
  • pdo_sqlite
  • pgsql
  • Phar
  • posix
  • readline
  • Reflection
  • session
  • SimpleXML
  • sockets
  • SPL
  • sqlite3
  • standard
  • tokenizer
  • xml
  • xmlreader
  • xmlwriter
  • Zend OPcache
  • zlib

and

  • Zend OPcache

@Mikulas
Copy link
Author

Mikulas commented Apr 4, 2017

I was not able to get mbstring working properly:

iconv(): Wrong charset, conversion from `UTF-8' to `ASCII//TRANSLIT//IGNORE' is not allowed

this is probably due to missing locales in alpine linux

@raul-guerrero
Copy link

pretty awesome thanks! Saved me tons of time and headaches

@mpolr
Copy link

mpolr commented Feb 29, 2020

Thanks a lot!

@arip-1990
Copy link

fix work iconv library with alphine

RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ --allow-untrusted gnu-libiconv
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment