Build and Run Laravel 7 in Docker Part 2 - PHP

Build and Run Laravel 7 in Docker Part 2 - PHP

Creating the App

Open your docker-compose.yml and paste the following. Notice the dockerfile line. We reference another file that will contain all our app information. Your working directory will be where your Laravel project will exist.

version: "3.7"

services:
# The Application
app: container_name: app build: context: ./ dockerfile: app.dockerfile working_dir: /var/www volumes: - ./:/var/www environment: CONTAINER_ROLE: app depends_on: - database environment: - "DB_PORT=3306" - "DB_HOST=database"

App.dockerfile

Within you root of Laravel create a file called app.dockerfile

touch app.dockerfile

In this example we will use php-fpm 7.2. Inside the app.dockerfile paste the following:

FROM php:7.2.5-fpm

RUN apt-get update && apt-get install -y libmcrypt-dev \
  mysql-client libmagickwand-dev --no-install-recommends \
  && docker-php-ext-install pdo_mysql \
  && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
  && docker-php-ext-install -j$(nproc) gd \
    && docker-php-ext-install zip 

RUN apt-get update \
  && apt-get install -y git \
    && apt-get install zip unzip

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

CMD docker-php-entrypoint php-fpm 

 

 

Part 3 - Adding Nginx to your docker build

Categories: Posts