LEMP : Nginx php-fpm mariadb with docker compose


docker compose

Dockerising, a LEMP stack ( Nginx Php-fpm and Mariadb ) with docker-compose on Linux . Please check out this post to see how the same can be done with docker command line .


Installation of docker-compose is covered in detail on official site,  do read through it . Pasting the quick howto  for debian here.

sudo apt-get install python-pip
sudo pip install --upgrade pip
sudo pip install docker-compose

Howto ::

  1. If you are following the last post you should now have the directory structure and conf files as below
    |-- mariadb
    | |-- data
    | | |-- ...
    | | `-- ...
    |-- nginx
    | |-- certs
    | |-- conf.d
    | | `-- techblog.com
    | |-- files
    | | |-- ...
    | | `-- ...
    | |-- log
    | | |-- ...
    | | `-- ...
    `-- phpfpm 
     |-- Dockerfile 
  2. Create  docker-compose.yml
    Create the docker-compose.yml file as below

    version: '3'
     image: mariadb:latest
     - ./mariadb/data:/var/lib/mysql
     - .env
     build: ./phpfpm/
     - ./nginx/files:/home/tech
     image: nginx:alpine
     - ./nginx/conf.d:/etc/nginx/conf.d 
     - ./nginx/certs:/etc/nginx/certs 
     - ./nginx/log:/var/log/nginx
     - ./nginx/files:/home/tech
     - 80:80
     - 443:443

    First line mentions the version of docker-compose syntax we are using. The later lines mentions the services and options they use, you can cross-reference them with the  docker commands used in the first post

  3. Make the LEMP stack online.
    docker-compose up -d 

    Above command will bring the 3 services mariadb, phpfpm and nginx online by deploying the respective  containers . Phpfpm container will be deployed after building the image with Dockerfile, rest of the services will be containerised from the base images. A bridge network will be auto created by the docker-compose and all the services will be added to it so that they can talk to each other.

  4. Monitoring/ Troubleshooting
    docker-compose ps 
    docker-compose top
    docker-compose logs
  5. Making the stack offline
    docker-compose down

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.