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
- 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
- Create docker-compose.yml
Create the docker-compose.yml file as below
version: '3' services: mariadb: image: mariadb:latest volumes: - ./mariadb/data:/var/lib/mysql env_file: - .env phpfpm: build: ./phpfpm/ volumes: - ./nginx/files:/home/tech nginx: image: nginx:alpine volumes: - ./nginx/conf.d:/etc/nginx/conf.d - ./nginx/certs:/etc/nginx/certs - ./nginx/log:/var/log/nginx - ./nginx/files:/home/tech ports: - 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
- 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.
- Monitoring/ Troubleshooting
docker-compose ps docker-compose top docker-compose logs
- Making the stack offline