For a setup using nginx-proxy. Based on another app, so commented code everywhere.
Database is available under host “mysql”
The volume for ‘config.php’ is not done correctly.
Welcoming feedback how to improve!
====docker-compose.yml====
version: ‘2’
services:
### Database Container ###
mysql:
image: mysql:5.7
command: mysqld –default-authentication-plugin=mysql_native_password
restart: always
environment:
– MYSQL_DATABASE=minthcm
– MYSQL_USER=minthcm
– MYSQL_PASSWORD=minthcm
– MYSQL_ROOT_PASSWORD=PaSsWoRd!!
volumes:
– ./volumes/mysql:/var/lib/mysql
# – ./minthcm.sql.gz:/docker-entrypoint-initdb.d/backup.sql.gz:ro
# use the above for restoring, when migrating to Docker.
networks:
– default
container_name: mysql_minthcm
### Applications Code Container ###
app:
build:
context: .
depends_on:
– mysql
expose:
– 80
environment:
– VIRTUAL_HOST=${DOMAIN}
– LETSENCRYPT_HOST=${DOMAIN}
# put these variables in a file named “.env”
volumes:
# – ./volumes/storage:/var/www/html/storage:rw
– ./volumes/config.php:/var/www/html/config.php:rw
networks:
– default
– nginx-proxy
container_name: app_minthcm
### Networks Setup ############################################
networks:
default:
driver: “bridge”
nginx-proxy:
external:
name: nginx-proxy
====Dockerfile====
FROM php:7.1-apache
# Instead of 7.1.1, to get something relatively updated
ENV APPHOST http://localhost:80
ENV APPHTTPS false
ENV DATABASE_NAME minthcm
ENV DATABASE_USERNAME minthcm
ENV DATABASE_PASSWORD minthcm
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y –install-recommends \
curl \
nano \
cron \
libzip-dev \
libz-dev \
libssl-dev \
libxml2-dev \
libssl-dev \
libmcrypt-dev \
libc-client-dev \
libkrb5-dev
# RUN rm -r /var/lib/apt/lists/*
# Install gd
#RUN apt-get install -y \
# libfreetype6-dev \
# libjpeg62-turbo-dev \
# libpng-dev \
# && docker-php-ext-configure gd –with-freetype-dir=/usr/include/ –with-jpeg-dir=/usr/include/ \
# && docker-php-ext-install gd
COPY php.ini “$PHP_INI_DIR/”
# make sure ‘php.ini’ is there, as php 7.1 docker does not have the below template files
#RUN mv “$PHP_INI_DIR/php.ini-production” “$PHP_INI_DIR/php.ini”
RUN pecl config-set php_ini “$PHP_INI_DIR/php.ini”
RUN ls -l “$PHP_INI_DIR/”
#RUN ls -l /usr/src/php/ext/
# Install the PHP mcrypt extention
#RUN pecl install mcrypt-1.0.4 \
# && echo “extension=mcrypt.so” > “$PHP_INI_DIR/php.ini”
# RUN docker-php-ext-install mcrypt
# Install mbstring
RUN docker-php-ext-install mbstring
# Install xml
RUN docker-php-ext-install xml
# Install xml
RUN docker-php-ext-configure imap –with-kerberos –with-imap-ssl
RUN docker-php-ext-install imap
# Install fileinfo
RUN docker-php-ext-install fileinfo
# Install the PHP pdo_mysql extention
RUN docker-php-ext-install mysqli \
&& docker-php-ext-install pdo_mysql
# Install zip
RUN apt-get install -y \
zlib1g-dev \
&& docker-php-ext-install zip
# Copy app code
COPY build /var/www/html/
# Copy error for DEBUG
# COPY build/error.ini /usr/local/etc/php/conf.d/
# Back custom folder
# RUN cp -r /var/www/html/custom /var/www/html/custom_back
# Configure cron job
# Add crontab file in the cron directory
RUN crontab -u www-data /var/www/html/crontab
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
# Reload cron
# RUN service cron reload
# Enable Apache mod_rewrite
RUN a2enmod rewrite
# Change Apache User
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
# Bind Apache User with our User – left it as is
RUN usermod –non-unique –uid 1000 www-data
RUN groupmod –non-unique –gid 1000 www-data
RUN chown -hR www-data:www-data /var/www/html
RUN chmod -R 755 /var/www/html
RUN chmod -R 775 custom modules themes data upload
CMD cron; apache2-foreground
RUN touch /var/www/html/config.php
RUN chmod 766 /var/www/html/config.php
# created after launching apache2, as it did not work when done before.
EXPOSE 80