Skip to content

Commit

Permalink
Add Docker configuration for running in container
Browse files Browse the repository at this point in the history
  • Loading branch information
zeevox committed Oct 9, 2023
1 parent e8cd313 commit 54de6f4
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
70 changes: 70 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
FROM php:7.4-apache

WORKDIR /var/www/html

# Hand over all of /var/www to www-data
RUN chown www-data:www-data /var/www

# enable error loggging
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
git \
curl \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libgd-dev \
jpegoptim optipng pngquant gifsicle \
libonig-dev \
libxml2-dev \
zip \
unzip && apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd

# Enable .htaccess files
RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf

# Set /public as served directory
ENV APACHE_DOCUMENT_ROOT /var/www/html/xelif/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# Enable rewrite module
RUN a2enmod rewrite

# Increase PHP memory limit
RUN echo 'memory_limit = 1G' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;

# Install PHP composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Leave superuser mode, switching to www-data user for dependency installation
USER www-data

# just copy everything over
WORKDIR /var/www/html/xelif
COPY --chown=www-data:www-data . .

RUN composer install \
--no-cache \
--no-interaction \
--no-plugins \
--no-scripts \
--no-dev \
--prefer-dist \
--optimize-autoloader \
--apcu-autoloader

RUN composer dump-autoload

RUN php artisan optimize:clear

EXPOSE 80
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3.8'

services:
xelif:
build:
context: .
dockerfile: Dockerfile
# Make sure database is started first
depends_on:
- xelif-db
# For debugging only
ports:
- 80:80
# For communication with database
networks:
- internal
container_name: xelif
volumes:
- "/srv/felix/uploads:/var/www/html/xelif/storage/app/public/uploads"
env_file:
- ".env"

xelif-db:
image: mysql
restart: always
container_name: xelif-db
volumes:
- "/opt/mysql:/var/lib/mysql"
- "/opt/mysqld.conf:/etc/mysql/conf.d/mysqld.conf"
networks:
- internal

networks:
internal:

0 comments on commit 54de6f4

Please sign in to comment.