Docker :: Docker-compose example

One example with a Standard Web application

1- Install Docker Compose … …………….. not include in Docker

  • curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  • chmod +x /usr/local/bin/docker-compose

 

2- Launch Docker- compose with the command

Docker-compose up -d

 

3- The file docker-compose.yml

# Adopt version 3 syntax:
# https://docs.docker.com/compose/compose-file/#/versioning
version: ‘3’

services:
###########################
# Setup the Apache container
###########################
httpd:
container_name: apache_docker
restart: always
image: httpd:2.4.38
ports:
– 80:80
volumes:
– ./apache/httpd.conf:/usr/local/apache2/conf/httpd.conf
– ./apache/vhosts/:/usr/local/apache2/conf/vhosts
depends_on:
– php

###########################
# Setup the PHP container ( with a Dockerfile  )
###########################
php:
container_name: php_docker
restart: always
build: ./php/
expose:
– 9000
volumes:
– ./www/:/usr/local/apache2/htdocs
– ./php/ssmtp.conf:/etc/ssmtp/ssmtp.conf:ro
– ./php/php-mail.conf:/usr/local/etc/php/conf.d/mail.ini:ro
depends_on:
– mysql

###########################
# Setup the MySQL container
###########################
mysql:
container_name: mysql_docker
restart: always
image: mysql:8.0.15
ports:
– 3306:3306
volumes:
– ./mysql/data2:/var/lib/mysql
– ./mysql/conf-mysql.cnf:/etc/mysql/mysql.conf.d/conf-mysql.cnf:ro
environment:
MYSQL_ROOT_PASSWORD: iado
MYSQL_DATABASE: iado
MYSQL_USER: project
MYSQL_PASSWORD: project

###########################
# Setup the phpmyadmin
###########################

phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: z_phpmyadmin
ports:
– 8080:80
links:
– mysql

 

4- the Dockerfile for PHP 

FROM php:7.1-apache

# Get repository and install wget and vim
RUN apt-get update && apt-get install –no-install-recommends -y \
wget \
gnupg \
git \
unzip

# Install PHP extensions deps
RUN apt-get update \
&& apt-get install –no-install-recommends -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
zlib1g-dev \
libicu-dev \
g++ \
unixodbc-dev \
libxml2-dev \
libaio-dev \
libmemcached-dev \
freetds-dev \
libssl-dev \
openssl

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

# Install PHP extensions
RUN docker-php-ext-configure gd –with-freetype-dir=/usr/include/ –with-jpeg-dir=/usr/include/ \
&& docker-php-ext-configure pdo_dblib –with-libdir=/lib/x86_64-linux-gnu \
&& pecl install sqlsrv-4.1.6.1 \
&& pecl install pdo_sqlsrv-4.1.6.1 \
&& pecl install redis \
&& pecl install memcached \
&& pecl install xdebug \
&& docker-php-ext-install \
iconv \
mbstring \
intl \
mcrypt \
gd \
mysqli \
pdo_mysql \
pdo_dblib \
soap \
sockets \
zip \
pcntl \
ftp \
&& docker-php-ext-enable \
sqlsrv \
pdo_sqlsrv \
redis \
memcached \
opcache \
xdebug

# Install APCu and APC backward compatibility
RUN pecl install apcu \
&& pecl install apcu_bc-1.0.3 \
&& docker-php-ext-enable apcu –ini-name 10-docker-php-ext-apcu.ini \
&& docker-php-ext-enable apc –ini-name 20-docker-php-ext-apc.ini

# Clean repository
RUN apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# The path that will be used to make Apache run under that user
ENV VOLUME_PATH /var/www/html/public

# Move files
COPY src/ /var/www/html/

COPY vhost.cnf /etc/apache2/sites-available/000-default.conf

WORKDIR /var/www/html/

RUN chown -R www-data:www-data /var/www/html/ \
&& a2enmod rewrite

 

5- Some commands usefull :

docker-compose down
docker rm $(docker ps -a -q)

 

Leave a Reply

Your email address will not be published. Required fields are marked *