Orchestrate Laravel apps with Docker compose

Source: Internet
Author: User
Tags nameserver docker compose install redis
This article mainly introduces the use of Docker compose Orchestration Laravel application, has a certain reference value, now share to everyone, the need for friends can refer to


Laravel Official development environment recommended is homestead (in fact, is a well-packaged vagrant box), I feel this is more heavy, so I used Docker compose to orchestrate a set of development environment, here to share.

Environmental requirements

Install Docker and Docker compose first, and Docker warehouse images are best for domestic. In general, I run a vagrant on my development computer and then run apps like Docker on the inside.

Main ideas

Docker officially recommends a container to run a service, so there will be compose orchestration, each service through the container interconnection technology communication, such as PHP service connection MySQL only use the host name as the container name, the internal will be directly converted to specific IP. The code catalog is mapped from the container to the host using a data volume, and the configuration file (Nginx, etc.) is also mapped to the container through the data volume.


This set of services I have already encapsulated, usually use only clone down direct use, I here mainly talk about the realization of ideas.

Project Address: https://github.com/rootrl/php ...

My project directory structure:

├──readme. Md

    • Bin here is a package of command-line tools, in fact, is the Docker container service, but they are all run out of service.

    • Conf The directory is the application's configuration directory and will be mapped to the container using volumn

    • Docker-composer.yaml compose of the layout of the document, the following will be specific

    • dockerfile.php PHP Image Build (there will be some customization, such as DNS, to install special extensions)

    • Start runs./start can start all services, reboot or run this command


This file is an orchestration file for compose

Version: ' 2 ' services:nginx:depends_on:-"php" Image: "Nginx" volumes:-"$PWD/CONF/NGINX/CONF.D:/ETC/NGINX/CONF.D "-" $PWD/www:/usr/share/nginx/html "ports:-" 8888:80 "networks:-oa-network container_name:" Oa-nginx "Comman D:/bin/bash-c "mkdir-p/var/www && ln-s/usr/share/nginx/html/var/www && nginx-g ' daemon off; '"   Php:image: "OA-PHP-FPM" Build:context:. Dockerfile: "dockerfile.php" networks:-oa-network container_name: "OA-PHP-FPM" volumes:-"$PWD/www:/var/www/html "mysql:image:mysql:5.7 volumes:-" $PWD/db_data:/var/lib/mysql "environment:MYSQL_ROOT_PASSWORD:root123 MySQL _database:oa Mysql_user:oa mysql_password:oa123 Ports:-"3306:3306" networks:-oa-network Container_name: "Oa-mysql" Redis:image: "Redis" Ports:-"6379:6379" networks:-oa-network Volumes:-"$PWD/conf/redis/redis.co Nf:/usr/local/etc/redis/redis.conf "Container_name:" Oa-redis "Networks:oa-network:driver:bridge

The PHP-FPM, Nignx, MySQL, and redis Four services are defined here (if additional services are required, add them yourself). A public networks is then defined so that the container can communicate easily.

Like nginx.conf.

server {    listen       ;    server_name  localhost;    Root/usr/share/nginx/html/public;    Index index.php index.html;    Location/{    try_files $uri $uri//index.php? $query _string;    }    Error_page   502 503 504  /50x.html;    Location =/50x.html {        root   /usr/share/nginx/html;    }    Location ~ \.php$ {        fastcgi_pass   php:9000;        Fastcgi_index  index.php;        Fastcgi_param  script_filename  /var/www/html/public/$fastcgi _script_name;        Include        fastcgi_params;    }}

How to connect with PHP-FPM here: php:9000


From PHP:7.2-FPM    Run echo "nameserver" >>/etc/resolv.conf \    && echo "nameserver ">>/etc/resolve.conf \    && apt-get update \    && apt-get install-y \        Libfreetype6-dev \        libjpeg62-turbo-dev \        libpng-dev \    && docker-php-ext-configure GD-- with-freetype-dir=/usr/include/--with-jpeg-dir=/usr/include/\    && docker-php-ext-install-j$ (nproc) GD \    && docker-php-ext-install mysqli pdo_mysql \    && pecl install swoole \    && pecl Install Redis \    && docker-php-ext-enable swoole Redis

This is the PHP image build, which changed the DNS server, and installed a number of PHP extensions.



./start Start All services

Command line

./bin/php-v# Laravel artisan./bin/php Artisan

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.