Skip to content

Instantly share code, notes, and snippets.

@abdala
Last active July 4, 2019 21:31
Show Gist options
  • Save abdala/ca703b68d6ec30b1bcd3bcb16df9da52 to your computer and use it in GitHub Desktop.
Save abdala/ca703b68d6ec30b1bcd3bcb16df9da52 to your computer and use it in GitHub Desktop.
Preload opcache in Dockerfile
opcache.validate_timestamps=0
opcache.save_comments=0
opcache.enable_cli=1
opcache.enable_file_override=1
opcache.file_cache=/app/opcache
#BASE
FROM alpine:3.9 as base
RUN apk add php7-pdo_mysql php7-curl php7-json php7-xml php7-tokenizer php7-simplexml
#DEPENDENCIES
FROM base as dependencies
WORKDIR /app
COPY composer.json /app/
COPY composer.lock /app/
RUN apk add composer php7-posix unzip \
&& composer global require hirak/prestissimo \
&& composer install --no-interaction --no-dev --no-autoloader
COPY . /app
#OPTIMIZED
FROM dependencies as optimized
COPY docker /
RUN apk add php7-opcache \
&& mkdir /app/opcache \
&& composer dump-autoload --classmap-authoritative --optimize
#CLI
FROM dependencies as cli
RUN apk add php7-xmlwriter \
&& composer install
#APP
FROM base
RUN apk add php7-apache2 php7-opcache
COPY docker /
COPY --from=optimized /app /app
EXPOSE 80
CMD httpd -DFOREGROUND
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment