Skip to content

Instantly share code, notes, and snippets.

@pc-magas
Created June 18, 2019 08:29
Show Gist options
  • Save pc-magas/75b30de0566f37d87024547cc15008b3 to your computer and use it in GitHub Desktop.
Save pc-magas/75b30de0566f37d87024547cc15008b3 to your computer and use it in GitHub Desktop.
Dockerfile form php developent and CI
ARG BASE_IMAGE=php:7.2-fpm-alpine
FROM ${BASE_IMAGE}
ARG USERID=1000
ARG GROUPID=1000
ENV DOCKER_UID=${USERID} \
DOCKER_GID=${GROUPID} \
PHP_CONF_DIR="/usr/local/etc/php/conf.d" \
FPM_CONF_DIR="/usr/local/etc/php-fpm.d" \
XDEBUG_CONF_FILE=${PHP_CONF_DIR}/docker-php-ext-xdebug.ini \
XDEBUG_HOST="" \
XDEBUG_IDE_KEY="" \
XDEBUG_PORT=9000 \
XDEBUG_DBGP=FALSE
RUN echo "Installing Development Dpendencies \n" &&\
echo http://dl-2.alpinelinux.org/alpine/edge/community/ >> /etc/apk/repositories &&\
apk add --update --virtual build-dependencies build-base gcc wget autoconf &&\
apk add --update bash shadow git bash-completion bash-doc &&\
echo "Installing composer \n" &&\
php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');" &&\
php -r "if (hash_file('sha384', '/tmp/composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" &&\
php /tmp/composer-setup.php --install-dir=/bin --filename=composer &&\
rm -rf /tmp/cpmposer-setup.php &&\
chmod +x /bin/composer &&\
echo "Installing xdebug" &&\
pecl install xdebug &&\
docker-php-ext-enable xdebug &&\
echo "Configuring Xdebug \n" &&\
echo "xdebug.remote_enable=1" >> ${XDEBUG_CONF_FILE} &&\
echo "xdebug.max_nesting_level = 1000" >> ${XDEBUG_CONF_FILE} &&\
echo "xdebug.remote_mode=req" >> ${XDEBUG_CONF_FILE} &&\
echo "xdebug.remote_log=xdebug.log" >> ${XDEBUG_CONF_FILE} &&\
cp ${XDEBUG_CONF_FILE} ${XDEBUG_CONF_FILE}.orig &&\
echo "Making a Development User \n" &&\
addgroup -g ${DOCKER_GID} developer &&\
mkdir -p /home/developer/code &&\
adduser -D -u ${DOCKER_UID} -G developer -h /home/developer -s /bin/bash developer &&\
chown developer:developer -R /home/developer/code &&\
apk del build-dependencies &&\
touch ${FPM_CONF_DIR}/dev.conf &&\
echo "[dev]" >> ${FPM_CONF_DIR}/dev.conf &&\
echo "listen = 0.0.0.0:9092" >> ${FPM_CONF_DIR}/dev.conf &&\
echo "user = developer" >> ${FPM_CONF_DIR}/dev.conf &&\
echo "group = developer" >> ${FPM_CONF_DIR}/dev.conf &&\
echo "pm = ondemand" >> ${FPM_CONF_DIR}/dev.conf &&\
echo "pm.max_children = 5" >> ${FPM_CONF_DIR}/dev.conf &&\
echo "pm.start_servers = 2" >> ${FPM_CONF_DIR}/dev.conf &&\
echo "pm.min_spare_servers = 1" >> ${FPM_CONF_DIR}/dev.conf &&\
echo "pm.max_spare_servers = 3" >> ${FPM_CONF_DIR}/dev.conf &&\
rm -rf /var/cache/apk/*
EXPOSE 9092
# I make seperate layer because Entrypoint is most likely to change
COPY ./entrypoint/develop_entrypoint.sh /usr/local/bin/entrypoint.sh
RUN echo "Fixing Permissions on Entrypoint Script \n" &&\
chown root:root /usr/local/bin/entrypoint.sh &&\
chmod +x /usr/local/bin/entrypoint.sh
VOLUME /home/developer/code
WORKDIR /home/developer/code
ENTRYPOINT /usr/local/bin/entrypoint.sh php-fpm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment