-
-
Save dsteindl/bc7295c9cc6612813a538c026efa0e14 to your computer and use it in GitHub Desktop.
Drupal 8/9 Basic Base-Dockerfile
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
# file ./apache2/000-default.conf | |
<VirtualHost *:80> | |
ServerAdmin development@liechtenecker.at | |
DocumentRoot /var/www/html/web | |
<Directory /var/www/html/web> | |
Options +FollowSymLinks -Indexes | |
AllowOverride All | |
</Directory> | |
RedirectMatch 404 /\.git | |
RedirectMatch 404 /\.env | |
ErrorLog ${APACHE_LOG_DIR}/error.log | |
CustomLog ${APACHE_LOG_DIR}/access.log combined | |
</VirtualHost> |
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
# set php:7.4-apache as parent image. | |
FROM php:7.4-apache | |
# set shell options (see documentation for more details) | |
RUN set -eux | |
# enable Apache2 rewrite module | |
RUN a2enmod rewrite | |
# copy the customized Apache2 vhost file from the project to the image | |
COPY ./apache2/000-default.conf /etc/apache2/sites-available/ | |
# copy custom php.ini overrides from the project to the image | |
COPY ./php/conf.d/* $PHP_INI_DIR/conf.d/ | |
# php:7.4 apache comes with 2 php.ini configurations: | |
# - $PHP_INI_DIR/php.ini-production | |
# - $PHP_INI_DIR/php.ini-development | |
# | |
# we choose the production one for our use-case | |
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" | |
# install dependencies | |
RUN apt-get update | |
RUN apt-get install -y --no-install-recommends libfreetype6-dev | |
RUN apt-get install -y --no-install-recommends libjpeg-dev | |
RUN apt-get install -y --no-install-recommends libpng-dev | |
RUN apt-get install -y --no-install-recommends libpq-dev | |
RUN apt-get install -y --no-install-recommends libzip-dev | |
RUN apt-get install -y --no-install-recommends g++ | |
RUN apt-get install -y --no-install-recommends libmemcached-dev | |
RUN apt-get install -y --no-install-recommends memcached | |
RUN apt-get install -y --no-install-recommends zip | |
RUN apt-get install -y --no-install-recommends unzip | |
RUN apt-get install -y --no-install-recommends curl | |
RUN apt-get install -y --no-install-recommends wget | |
RUN apt-get install -y --no-install-recommends vim | |
RUN apt-get install -y --no-install-recommends mariadb-client | |
RUN apt-get install -y --no-install-recommends autoconf | |
RUN apt-get install -y --no-install-recommends sudo | |
RUN apt-get install -y --no-install-recommends zsh | |
RUN apt-get install -y --no-install-recommends git | |
# install the pecl extension “memcached” | |
RUN pecl install memcached | |
# the base-image comes with the helpers | |
# - docker-php-ext-enable | |
# - docker-php-ext-configure | |
# - docker-php-ext-install | |
# enable memcached and configure gd | |
RUN docker-php-ext-enable memcached | |
RUN docker-php-ext-configure gd | |
# install required php-extensions | |
RUN docker-php-ext-install -j "$(nproc)" \ | |
gd \ | |
opcache \ | |
pdo_mysql \ | |
pdo_pgsql \ | |
zip | |
# set recommended op-cache php.ini settings | |
# see https://secure.php.net/manual/en/opcache.installation.php | |
RUN { \ | |
echo 'opcache.memory_consumption=128'; \ | |
echo 'opcache.interned_strings_buffer=8'; \ | |
echo 'opcache.max_accelerated_files=4000'; \ | |
echo 'opcache.revalidate_freq=60'; \ | |
echo 'opcache.fast_shutdown=1'; \ | |
} > /usr/local/etc/php/conf.d/opcache-recommended.ini | |
# we want our www-data user to run as user-id 1000 and the group www-data to be group-id 1000 | |
ENV PUID 1000 | |
ENV PGID 1000 | |
RUN groupmod -o -g 1000 www-data | |
RUN usermod -o -u 1000 -g www-data www-data | |
# set environment variables | |
ENV EDITOR='vim' | |
ENV DRUPAL_ROOT=/var/www/html | |
ENV SERVER_ROOT=/var/www/html/web | |
# copy the custom startup-script into the image | |
COPY ./scripts/startup-script.sh /usr/local/bin/startup-script | |
RUN chmod +x /usr/local/bin/startup-script | |
# run the autoremove to remove unused packages | |
RUN apt-get autoremove -y | |
# cleanup & delete all package lists | |
RUN apt-get clean && \ | |
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ | |
rm /var/log/lastlog /var/log/faillog | |
# install composer globally | |
RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer | |
# composer installs at version 2 on default. | |
# in my experience, it’s not a good idea to use composer 2 now. Drupal and some modules are not ready yet. | |
RUN composer self-update --1 | |
RUN echo "export PATH=\"$HOME/.composer/vendor/bin:$PATH\"" >> ~/.bashrc | |
# install cgr & drush globally | |
RUN composer global require consolidation/cgr | |
RUN /bin/bash -c "$HOME/.composer/vendor/bin/cgr drush/drush" | |
# set the work directory to /var/www/html (this is the webroot) | |
# when someone connects, this will be the starting-point | |
WORKDIR /var/www/html | |
# override the default CMD statement from php:7.4-apache, to be able to execute additional logic before starting the apache2 server | |
# it was [“apache2-foreground”] | |
# do not forget to call call this command in startup-script | |
CMD ["startup-script"] | |
# expose the port 80, so users can access Drupal via http | |
EXPOSE 80 |
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
; file ./php/conf.d/memory_imit.ini | |
memory_limit=2048M |
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
#!/bin/bash | |
# file: scripts/startup-script.sh | |
echo " [info] Startup memcached server in background." | |
memcached -u root -m 256 -d | |
echo " [info] Start the apache2 server in foreground." | |
apache2-foreground |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment