Skip to content

Instantly share code, notes, and snippets.

@rstriquer
Last active March 15, 2022 12:44
Show Gist options
  • Save rstriquer/69a328b6c2dac9d26e9867f3aac96157 to your computer and use it in GitHub Desktop.
Save rstriquer/69a328b6c2dac9d26e9867f3aac96157 to your computer and use it in GitHub Desktop.
PHP Dockerfile
# inspired on https://gist.github.com/Mikulas/449746102591d636640467910eaf8aad
# https://www.digitalocean.com/community/tutorials/how-to-install-and-set-up-laravel-with-docker-compose-on-ubuntu-20-04-pt
FROM php:8.1.3-alpine AS php8.1-local
# Arguments defined in docker-compose.yml
ARG user
ARG uid
ARG gid
RUN echo "UTC" > /etc/timezone
RUN apk add bash
RUN sed -i 's/bin\/ash/bin\/bash/g' /etc/passwd
RUN set -xe && apk add --no-cache --update --virtual .phpize-deps $PHPIZE_DEPS
RUN set -xe && apk add --no-cache --update --virtual zip unzip curl npm \
autoconf g++ libtool make icu-dev
RUN docker-php-ext-install pdo_mysql opcache pcntl bcmath
RUN pecl install redis && docker-php-ext-enable redis
RUN apk add --update --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev libwebp-dev \
&& docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
--with-webp \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
&& docker-php-ext-install -j$(nproc) gd \
&& apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-dev
ENV XDEBUG_MODE=off
ENV XDEBUG_CONFIG=""
RUN pecl install xdebug && docker-php-ext-enable xdebug
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN addgroup -g $gid $user
RUN adduser --disabled-password --gecos "" -G $user -u $uid -h /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Installing composer
RUN curl -sS https://getcomposer.org/installer -o composer-setup.php
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN rm -rf composer-setup.php
RUN apk del autoconf bash binutils db expat file g++ gcc gdbm gmp isl libatomic \
libbz2 libc-dev libffi libgcc libgomp libldap libltdl libmagic libsasl \
libstdc++ libtool m4 make mpc1 musl-dev perl pkgconf pkgconfig re2c \
readline sqlite-libs zlib-dev
RUN rm -rf /tmp/* /var/cache/apk/*
USER $user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment