Skip to content

Commit cc3484b

Browse files
Update README.md
1 parent 57f20a8 commit cc3484b

1 file changed

Lines changed: 164 additions & 3 deletions

File tree

README.md

Lines changed: 164 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ and MySql image that they can update as per their requirements.
3030
```
3131
docker-compose up -d
3232
```
33-
2. If everthing goes well, you will see below message:
33+
2. If it runs successfully, you will see below message:
3434
```
3535
Creating php ... done
3636
Creating mysql ... done
@@ -185,8 +185,6 @@ $databases['default']['default'] = array (
185185
);
186186
```
187187

188-
--WIP---
189-
190188
## Directory Structure
191189
Once you clone this respository, it comes with default index.php in docroot folder. Inside this docroot, you can replace it with your existing project codebase. For example, I have added drupal8 codebase that looks like below:
192190
```
@@ -212,6 +210,169 @@ Once you clone this respository, it comes with default index.php in docroot fold
212210
└── php
213211
└── Dockerfile
214212
```
213+
## Docker Files Explanation
214+
Docker files define a sets of services which make up an entire application. It allows you to define the dependencies for those services, networks and volumes etc.
215+
216+
#### docker-compose.yml
217+
```
218+
version: "3.2"
219+
services:
220+
php:
221+
build:
222+
context: './php/'
223+
args:
224+
PHP_VERSION: ${PHP_VERSION}
225+
networks:
226+
- backend
227+
volumes:
228+
- ${PROJECT_ROOT}/:/var/www/html/
229+
container_name: php
230+
apache:
231+
build:
232+
context: './apache/'
233+
args:
234+
APACHE_VERSION: ${APACHE_VERSION}
235+
depends_on:
236+
- php
237+
- mysql
238+
networks:
239+
- frontend
240+
- backend
241+
ports:
242+
- "80:80"
243+
volumes:
244+
- ${PROJECT_ROOT}/:/var/www/html/
245+
container_name: apache
246+
mysql:
247+
image: mysql:${MYSQL_VERSION:-latest}
248+
restart: always
249+
ports:
250+
- "3306:3306"
251+
volumes:
252+
- data:/var/lib/mysql
253+
networks:
254+
- backend
255+
environment:
256+
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
257+
MYSQL_DATABASE: "${DB_NAME}"
258+
MYSQL_USER: "${DB_USERNAME}"
259+
MYSQL_PASSWORD: "${DB_PASSWORD}"
260+
container_name: mysql
261+
networks:
262+
frontend:
263+
backend:
264+
volumes:
265+
data:
266+
267+
```
268+
Here version is Docker version. It has php, apache and mysql services. To avoid any custom image for PHP and apache, we are using context here to define the PHP & Apache dockerfile separately. In case of Mysql, we are directly downloading the MySql image because MySql container doesn't require any special library or configuration. You may create a separate Dockerfile for MySql if it's required in your case.
269+
270+
#### Apache Dockerfile
271+
```
272+
ARG APACHE_VERSION=""
273+
FROM httpd:${APACHE_VERSION:+${APACHE_VERSION}-}alpine
274+
275+
RUN apk update; \
276+
apk upgrade;
277+
278+
# Copy apache vhost file to proxy php requests to php-fpm container
279+
COPY local.apache.conf /usr/local/apache2/conf/local.apache.conf
280+
RUN echo "Include /usr/local/apache2/conf/local.apache.conf" \
281+
>> /usr/local/apache2/conf/httpd.conf
282+
```
283+
It downloads the apache image for the version defined in `.env` file. In our case, it's `2.4.41`. You can change it as per your requirements.
284+
285+
#### PHP Dockerfile
286+
287+
```
288+
ARG PHP_VERSION=""
289+
FROM php:${PHP_VERSION:+${PHP_VERSION}-}fpm-alpine
290+
291+
RUN apk update; \
292+
apk upgrade;
293+
294+
# Install gd library extension
295+
RUN apk add libpng libpng-dev libjpeg-turbo-dev libwebp-dev zlib-dev libxpm-dev gd && docker-php-ext-install gd
296+
297+
# Install MySql
298+
RUN docker-php-ext-install mysqli pdo pdo_mysql
299+
300+
# Install Composer
301+
RUN curl -sS https://getcomposer.org/installer | php && \
302+
mv composer.phar /usr/local/bin/composer && \
303+
ln -s /root/.composer/vendor/bin/drush /usr/local/bin/drush
304+
305+
# Install Drush
306+
RUN composer global require drush/drush && \
307+
composer global update
308+
309+
# PHP packages
310+
RUN apk add --update \
311+
libressl \
312+
ca-certificates \
313+
openssh-client \
314+
rsync \
315+
git \
316+
curl \
317+
wget \
318+
gzip \
319+
tar \
320+
patch \
321+
perl \
322+
pcre \
323+
imap \
324+
imagemagick \
325+
mariadb-client \
326+
build-base \
327+
autoconf \
328+
libtool \
329+
php7-dev \
330+
pcre-dev \
331+
imagemagick-dev \
332+
php7 \
333+
php7-fpm \
334+
php7-opcache \
335+
php7-session \
336+
php7-dom \
337+
php7-xml \
338+
php7-xmlreader \
339+
php7-ctype \
340+
php7-ftp \
341+
php7-gd \
342+
php7-json \
343+
php7-posix \
344+
php7-curl \
345+
php7-pdo \
346+
php7-pdo_mysql \
347+
php7-sockets \
348+
php7-zlib \
349+
php7-mcrypt \
350+
php7-mysqli \
351+
php7-sqlite3 \
352+
php7-bz2 \
353+
php7-phar \
354+
php7-openssl \
355+
php7-posix \
356+
php7-zip \
357+
php7-calendar \
358+
php7-iconv \
359+
php7-imap \
360+
php7-soap \
361+
php7-dev \
362+
php7-pear \
363+
php7-redis \
364+
php7-mbstring \
365+
php7-xdebug \
366+
php7-exif \
367+
php7-xsl \
368+
php7-ldap \
369+
php7-bcmath \
370+
php7-memcached \
371+
php7-oauth \
372+
php7-apcu
373+
```
374+
It downloads the php image for the version defined in `.env` file. In our case, it's `7.3`. You can change it as per your requirements. Also, I have added all the minimal PHP libraries along with Composer and Drush to ensure we don't face any issue with core Drupal 8. You may add/update/delete any library in PHP dockerfile as per your requirements.
375+
215376
## Important Docker commands
216377
* ``docker-compose up`` Start all the containers.
217378
* ``docker-compose down`` Stop all the containers.

0 commit comments

Comments
 (0)