Skip to content

Instantly share code, notes, and snippets.

@lstellway
Last active May 5, 2024 04:58
Show Gist options
  • Save lstellway/19441a4a0de81828c7fa5b7e6d254eb0 to your computer and use it in GitHub Desktop.
Save lstellway/19441a4a0de81828c7fa5b7e6d254eb0 to your computer and use it in GitHub Desktop.
FROM alpine:3.19.1 as base
LABEL Description="NGINX & PHP 8.x on Alpine Linux"
LABEL org.opencontainers.image.source=https://github.com/builtforbackroads/admin-wp
WORKDIR /var/www/html
# System dependencies
RUN apk update \
&& apk add --no-cache \
curl \
nginx \
supervisor \
gifsicle jpegoptim pngquant \
php83 php83-fpm php83-bcmath php83-ctype php83-curl php83-dom php83-exif php83-fileinfo php83-gd php83-iconv php83-intl php83-json php83-mbstring php83-mysqli php83-opcache php83-pdo_mysql php83-phar php83-session php83-simplexml php83-soap php83-sockets php83-tokenizer php83-xmlreader php83-xmlwriter php83-xsl php83-zip php83-zlib
# Create symlinks
RUN \
([ -f "/usr/bin/php" ] || ln -s "/usr/bin/php83" "/usr/bin/php") \
&& PHP_FPM=$(which php-fpm83) \
&& (command -v php-fpm || ln -s "${PHP_FPM}" "${PHP_FPM/83/}")
# 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 \
/run \
/var/lib/nginx \
/var/log/nginx \
/var/log/php83
# Expose the port nginx is reachable on
EXPOSE 80
# build
FROM base as builder
ARG ACF_PRO_KEY=
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN apk add --no-cache \
git patch npm \
build-base autoconf automake
# Switch to use a non-root user
USER nobody
# Install composer dependencies
COPY --chown=nobody composer.* ./
RUN printf "ACF_PRO_KEY=${ACF_PRO_KEY}" > "/var/www/html/.env" \
&& composer install --optimize-autoloader --no-scripts --no-interaction \
&& rm -f "/var/www/html/.env"
####################
# production stage #
####################
FROM base AS prod
# Add configurations
COPY --from=builder --chown=nobody "/var/www/html" "/var/www/html"
COPY .dev/build/nginx.conf /etc/nginx/nginx.conf
COPY .dev/build/fpm-pool.conf /etc/php83/php-fpm.d/www.conf
COPY .dev/build/php.ini /etc/php83/conf.d/custom.ini
COPY .dev/build/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY --chown=nobody . .
USER nobody
# Let supervisord start nginx & php-fpm
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
# Configure a healthcheck to validate that everything is up&running
HEALTHCHECK --timeout=10s CMD curl --silent --fail http://127.0.0.1:8080/fpm-ping
@lstellway
Copy link
Author

# docker-compose.yml
---
version: "3"
services:
  bfb-mariadb:
    container_name: bfb-mariadb
    environment:
      MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
    image: mariadb:10.11.6
    networks:
      bfb:
        aliases:
          - mariadb
    ports:
      - 30606:3306
    volumes:
      - bfb-mariadb:/var/lib/mysql:z

  bfb-admin:
    container_name: bfb-admin
    build:
      context: .
      dockerfile: Dockerfile
      args:
        ACF_PRO_KEY: ${ACF_PRO_KEY}
    environment:
      ENV: /etc/profile
      HOME: /var/www/html
    networks:
      bfb:
    ports:
      - 8080:8080
    restart: unless-stopped
    volumes:
      - .:/var/www/html:z
      - .dev/build/php.dev.ini:/etc/php8/conf.d/custom.ini:z,ro
      - .dev/.profile:/etc/profile.d/profile.sh

networks:
  bfb:
    name: bfb

volumes:
  bfb-mariadb:
    name: bfb-mariadb

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