Created
May 7, 2021 16:54
-
-
Save yohangdev/624947d9ad896d9d353e49c79a5706c5 to your computer and use it in GitHub Desktop.
Dockerfile PHP 8 & Newrelic Agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine:3.13 | |
LABEL Maintainer="Yoga Hanggara <[email protected]>" \ | |
Description="Lightweight Laravel app container with Nginx 1.18 & PHP-FPM 8 based on Alpine Linux." | |
ARG PHP_VERSION="8.0.2-r0" | |
# Install packages | |
RUN apk --no-cache add php8=${PHP_VERSION} php8-fpm php8-opcache php8-openssl php8-curl php8-phar php8-session \ | |
php8-fileinfo php8-pdo php8-pdo_mysql php8-mysqli php8-mbstring php8-dom \ | |
nginx supervisor curl | |
# Symlink php8 => php | |
RUN ln -s /usr/bin/php8 /usr/bin/php | |
# Configure nginx | |
COPY docker/nginx.conf /etc/nginx/nginx.conf | |
# Remove default server definition | |
RUN rm /etc/nginx/conf.d/default.conf | |
# Configure PHP-FPM | |
COPY docker/fpm-pool.conf /etc/php8/php-fpm.d/www.conf | |
COPY docker/php.ini /etc/php8/conf.d/custom.ini | |
# Configure supervisord | |
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf | |
# install new relic | |
RUN curl -L "https://download.newrelic.com/php_agent/release/newrelic-php5-9.17.1.301-linux-musl.tar.gz" | tar -C /tmp -zx \ | |
&& export NR_INSTALL_SILENT=1 \ | |
&& export NR_INSTALL_USE_CP_NOT_LN=1 \ | |
&& /tmp/newrelic-php5-*/newrelic-install install \ | |
&& rm -rf /tmp/newrelic-php5-* /tmp/nrinstall* | |
RUN echo "newrelic.enabled=true" >> /etc/php8/conf.d/newrelic.ini \ | |
&& echo "newrelic.license=\"XXXXX\"" >> /etc/php8/conf.d/newrelic.ini \ | |
&& echo "newrelic.appname=\"PHP Application\"" >> /etc/php8/conf.d/newrelic.ini \ | |
&& echo "newrelic.daemon.address=\"php-newrelic-daemon:31339\"" >> /etc/php8/conf.d/newrelic.ini | |
# Setup document root | |
RUN mkdir -p /var/www/html | |
COPY docker/docker-entrypoint.sh docker-entrypoint.sh | |
RUN chmod +x docker-entrypoint.sh | |
# Make sure files/folders needed by the processes are accessable when they run under the nobody user | |
RUN chown -R nobody.nobody /var/www/html && \ | |
chown -R nobody.nobody /run && \ | |
chown -R nobody.nobody /var/lib/nginx && \ | |
chown -R nobody.nobody /var/log/nginx | |
# Switch to use a non-root user from here on | |
USER nobody | |
# Add application | |
WORKDIR /var/www/html | |
COPY --chown=nobody . /var/www/html | |
# Install composer from the official image | |
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer | |
# Run composer install to install the dependencies | |
RUN composer install --no-cache --no-dev --prefer-dist --optimize-autoloader --no-interaction --no-progress && \ | |
composer dump-autoload --optimize | |
# Expose the port nginx is reachable on | |
EXPOSE 8080 | |
# Let supervisord start nginx & php-fpm | |
ENTRYPOINT ["/bin/sh", "/docker-entrypoint.sh"] | |
# Configure a healthcheck to validate that everything is up&running | |
HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment