This commit is contained in:
Andrei Condurachi 2020-11-20 15:37:36 +02:00
parent 7194097708
commit fff99721a0
3 changed files with 93 additions and 46 deletions

View File

@ -1,52 +1,41 @@
FROM php:7.4-fpm
FROM alpine
# Ubuntu repo updates
RUN apt-get update
# Initial updates
RUN apk update && \
apk upgrade && \
rm -rf /var/cache/apk/* /var/log/*
# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
apt-utils \
apache2 \
unzip \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libyaml-dev \
libzip4 \
libzip-dev \
zlib1g-dev \
libicu-dev \
libmemcached11 \
libmemcachedutil2 \
build-essential \
libmemcached-dev \
g++ \
git \
cron \
vim \
&& docker-php-ext-install opcache \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install zip \
&& rm -rf /var/lib/apt/lists/*
# Install packages
RUN apk add apache2 apache2-proxy composer zip curl
# Enable Apache Rewrite + Expires Module
RUN a2enmod rewrite expires && \
sed -i 's/ServerTokens OS/ServerTokens ProductOnly/g' \
/etc/apache2/conf-available/security.conf
# Configure to use php fpm and don't use /var/www to store everything (modules and logs)
RUN sed -i 's/LoadModule mpm_prefork_module/#LoadModule mpm_prefork_module/g' /etc/apache2/httpd.conf && \
sed -i 's/#LoadModule mpm_event_module/LoadModule mpm_event_module/g' /etc/apache2/httpd.conf && \
sed -i 's/#LoadModule rewrite_module/LoadModule rewrite_module/g' /etc/apache2/httpd.conf && \
# remove useless module bundled with proxy
sed -i 's/LoadModule lbmethod/#LoadModule lbmethod/g' /etc/apache2/conf.d/proxy.conf && \
# change ServerRoot
sed -i 's/var\/www\/localhost\/htdocs/var\/www/g' /etc/apache2/httpd.conf && \
sed -i 's/ServerRoot \/var\/www/ServerRoot \/usr\/local\/apache/g' /etc/apache2/httpd.conf && \
# change user and group
sed -i 's/^User apache/User www-data/g' /etc/apache2/httpd.conf && \
sed -i 's/^Group apache/Group www-data/g' /etc/apache2/httpd.conf && \
# Prepare env and create user
mkdir -p /var/log/apache2 && \
groupdel www-data && \
groupmod -g 101 -n www-data apache && \
usermod -g 101 -u 100 -l www-data -d /var/www apache && \
chown www-data:www-data /var/log/apache2 /var/www && \
# Clean base directory and create required ones
rm -rf /var/www/* && \
mkdir -p /run/apache2 /usr/local/apache && \
ln -s /usr/lib/apache2 /usr/local/apache/modules && \
ln -s /var/log/apache2 /usr/local/apache/logs
# Install composer
RUN curl --silent --show-error https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
COPY vhost.conf /etc/apache2/conf.d/vhost.conf
RUN pecl install apcu \
&& pecl install yaml-2.1.0 \
&& docker-php-ext-enable apcu yaml gd opcache intl zip
# Set user to www-data
RUN chown www-data:www-data /var/www
USER www-data
ENV APACHE_UID 100
ENV APACHE_GID 101
# Define Grav specific version of Grav or use latest stable
ENV GRAV_VERSION latest
@ -68,6 +57,9 @@ EXPOSE 80/tcp
USER root
# provide container inside image for data persistence
VOLUME ["/var/www/html"]
VOLUME ["/var/www"]
CMD ["sh", "-c", "apache2-foreground"]
COPY run.sh /run.sh
RUN chmod u+x /run.sh
CMD ["/run.sh"]

10
run.sh Normal file
View File

@ -0,0 +1,10 @@
#!/bin/sh
CURRENT_APACHE_ID=$(id -u www-data)
if [ "$CURRENT_APACHE_ID" != "$APACHE_UID" ]; then
echo "Fixing permissions for www-data"
usermod -u $APACHE_UID www-data
groupmod -g $APACHE_GID www-data
chown -R www-data:www-data /run/apache2 /var/www
fi
exec /usr/sbin/httpd -DFOREGROUND;

45
vhost.conf Normal file
View File

@ -0,0 +1,45 @@
ServerName localhost
<VirtualHost *:80>
ServerName localhost
## Vhost docroot
DocumentRoot /var/www
## Take .htaccess.local in priority
AccessFileName .htaccess.local .htaccess
## PHP-FPM connection
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/$1
DirectoryIndex index.php
## Directories,
<LocationMatch "^(.*/)\..*">
Require all denied
</LocationMatch>
<FilesMatch "^\.">
Require all denied
</FilesMatch>
<DirectoryMatch "^(.*/)\..*">
Require all denied
</DirectoryMatch>
<Directory "/var/www">
Options -Indexes +FollowSymLinks +IncludesNOEXEC -MultiViews
AllowOverride All
Require all granted
<FilesMatch ".+(\.php)$">
SetHandler "proxy:fcgi://php:9000"
</FilesMatch>
</Directory>
<Proxy "fcgi://php:9000">
ProxySet timeout=1200
</Proxy>
## Logging : hide version
ServerSignature Off
</VirtualHost>