This Dockerfile builds a PHP 7.0 Apache image with additional dependencies and configurations, including installing Composer, configuring Apache, and generating a self-signed SSL certificate. It also sets environment variables and copies web content and configuration files to the image, ultimately creating a customized PHP development environment.
FROM php:7.0-apache
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN rm -rf /var/www/html/logs/* \
&& chown -R www-data:www-data /var/www/html
RUN a2enmod ssl
RUN a2enmod rewrite
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -subj "/C=UK/ST=Warwickshire/L=Leamington/O=OrgName/OU=IT Department/CN=SCO-100001269.ad.swiftpage.com" -keyout /etc/ssl/private/mysitename.key -out /etc/ssl/private/mysitename.crt
COPY ./web /var/www/html
COPY ./site.conf.ini /etc/apache2/sites-enabled/000-default.conf
COPY chain.crt /etc/ssl/private/
COPY TrustedRoot.crt /etc/ssl/private/
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_RUN_DIR /var/run/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
RUN echo "ServerName SCO-100001269.ad.swiftpage.com" >> /etc/apache2/apache2.conf
RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
bash
# Base image for PHP 7.0 with Apache
FROM php:7.0-apache
# Update and install dependencies
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& apt-get clean -y
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& composer self-update
# Remove logs and reset ownership
RUN rm -rf /var/www/html/logs/* \
&& chown -R www-data:www-data /var/www/html
# Enable SSL and rewrite modules
RUN a2enmod ssl
RUN a2enmod rewrite
# Generate SSL certificate and key (TODO: Use a more secure method for generating the certificate)
# Note: The certificate and key are generated with default values for simplicity.
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -subj "/C=UK/ST=Warwickshire/L=Leamington/O=OrgName/OU=IT Department/CN=SCO-100001269.ad.swiftpage.com" -keyout /etc/ssl/private/mysitename.key -out /etc/ssl/private/mysitename.crt \
&& openssl x509 -in /etc/ssl/private/mysitename.crt -text -noout
# Copy application files and configuration
COPY./web /var/www/html
COPY./site.conf.ini /etc/apache2/sites-enabled/000-default.conf
# Copy SSL certificates
COPY chain.crt /etc/ssl/private/
COPY TrustedRoot.crt /etc/ssl/private/
# Set up environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_RUN_DIR /var/run/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
# Configure Apache (TODO: Use a more secure method for setting the ServerName)
# Note: The ServerName is set with a default value for simplicity.
RUN echo "ServerName SCO-100001269.ad.swiftpage.com" >> /etc/apache2/apache2.conf
# Create directories for Apache
RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
Dockerfile Breakdown
The provided code is a Dockerfile that builds a PHP 7.0 Apache image with additional dependencies and configurations.
FROM php:7.0-apache
: Use the official PHP 7.0 Apache image as a base.RUN apt-get update && apt-get install -y
: Update package list and install necessary packages.
libfreetype6-dev
libjpeg62-turbo-dev
libmcrypt-dev
libpng12-dev
docker-php-ext-install -j$(nproc) iconv mcrypt
: Install iconv and mcrypt extensions.docker-php-ext-configure gd
: Configure gd extension.docker-php-ext-install -j$(nproc) gd
: Install gd extension.RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
: Install Composer using the official installer.RUN rm -rf /var/www/html/logs/*
RUN chown -R www-data:www-data /var/www/html
RUN a2enmod ssl
: Enable SSL module.RUN a2enmod rewrite
: Enable rewrite module.RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -subj...
COPY./web /var/www/html
COPY./site.conf.ini /etc/apache2/sites-enabled/000-default.conf
COPY chain.crt /etc/ssl/private/
and COPY TrustedRoot.crt /etc/ssl/private/
APACHE_RUN_USER
APACHE_RUN_GROUP
APACHE_LOG_DIR
APACHE_PID_FILE
APACHE_RUN_DIR
APACHE_LOCK_DIR
RUN echo "ServerName SCO-100001269.ad.swiftpage.com" >> /etc/apache2/apache2.conf
RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR