Docker for PHP Laravel (Dockerfile and docker-compose.yaml)

Php

Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
FROM php:7-apache

WORKDIR /var/www/html

# git: for php package barryvdh/laravel-debugbar
# zip, unzip: for composer download from dist
# libmagickwand-dev: for intervention/image and php7-imagick
# ssh: ssh client for git-ssh
RUN apt-get update && apt-get install -y \
$PHPIZE_DEPS \
ca-certificates \
curl \
xz-utils \
git \
zip unzip\
libzip-dev \
libmagickwand-dev \
ssh \
--no-install-recommends && rm -r /var/lib/apt/lists/*

# imagick: for intervention/image
RUN pecl install imagick

# pdo_mysql, bcmath: officail laravel requirement
# fileinfo, imagick: for php package intervention/image
RUN docker-php-ext-install pdo_mysql bcmath zip
RUN docker-php-ext-enable imagick


RUN a2enmod rewrite

COPY apache2.000-default.conf /etc/apache2/sites-enabled/000-default.conf

# xdebug
#RUN apt-get update &&\
# apt-get install --no-install-recommends --assume-yes --quiet ca-certificates curl git &&\
# rm -rf /var/lib/apt/lists/*
#
#RUN pecl install xdebug && docker-php-ext-enable xdebug

docker-compose.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
version: '3'

services:
# docker run --rm -it --net myNetwork -v $(pwd):/var/www/html -p 10080:80 --name localhost-cms-backend-v2 localhost/cms_backend_v2
api:
# container_name: localhost-cms-backend-v2
build: .
ports:
- "10080:80"
volumes:
- .:/var/www/html
- ~/.ssh:/root/.ssh
db:
# container_name: db
image: mariadb:10.3.15-bionic
ports:
- "13306:3306"
# volumes:
# - ../../Storage/mysql:/var/lib/mysql
environment:
- MYSQL_DATABASE=my_db
- MYSQL_ROOT_PASSWORD=123456!

# docker run --name redis --net myNetwork -d -t -p 6379:6379 redis
redis:
# container_name: redis
image: redis:5.0.5-stretch
ports:
- "6379:6379"

apache2.000-default.conf

1
2
3
4
5
6
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html/public # set default doccument root to `/var/www/html/public`
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>