Skip to content

Commit

Permalink
Cleanup Dockerfile
Browse files Browse the repository at this point in the history
- Add divider comment between generic and specific sections
- Grab composer from official docker image rather than web
- Use a more robust shell
- Make apt-install footprint smaller
- Use OpenSSL with paths rather than use WORKDIR
- Make project path setable through env var for build purposes
- Only install non-dev dependencies with composer. The develop shoudl consciencely install deve dependencies because of develop PHP version(s) used.
- Use COPY rather than ADD as per best practices
  • Loading branch information
Potherca committed Dec 13, 2021
1 parent d2c59df commit 396d93f
Showing 1 changed file with 46 additions and 22 deletions.
68 changes: 46 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
FROM php:7.3-apache
RUN apt-get update && \
apt-get install -y \

# ==============================================================================
# Set up the machine
# ------------------------------------------------------------------------------
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update && \
apt-get install -y --no-install-recommends \
git \
libzip-dev \
zlib1g-dev
WORKDIR /tls
RUN openssl req -new -x509 -days 365 -nodes \
-out server.cert \
-keyout server.key \
-subj "/C=RO/ST=Bucharest/L=Bucharest/O=IT/CN=www.example.ro"
RUN docker-php-ext-install mysqli pdo pdo_mysql zip mbstring bcmath
RUN a2enmod rewrite
RUN a2enmod ssl
RUN a2enmod headers
WORKDIR /install
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
ADD . /app
WORKDIR /app
RUN php /install/composer.phar require lcobucci/jwt:3.3.3
RUN php /install/composer.phar update
RUN php /install/composer.phar install
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir /tls && openssl req -new -x509 -days 365 -nodes \
-out /tls/server.cert \
-keyout /tls/server.key \
-subj "/C=NL/ST=Overijssel/L=Enschede/O=PDS Interop/OU=IT/CN=pdsinterop.org"

RUN docker-php-ext-install \
bcmath \
mbstring \
mysqli \
pdo \
pdo_mysql \
zip

RUN a2enmod headers rewrite ssl

COPY site.conf /etc/apache2/sites-enabled/site.conf
RUN chown -R www-data:www-data /app

WORKDIR /app

EXPOSE 443
# ==============================================================================


# ==============================================================================
# Add the source code
# ------------------------------------------------------------------------------
ARG PROJECT_PATH
RUN : "${PROJECT_PATH:=$PWD}"

COPY "${PROJECT_PATH}" /app/

RUN composer install --no-dev --prefer-dist
RUN chown -R www-data:www-data /app
# ==============================================================================

0 comments on commit 396d93f

Please sign in to comment.