使用Docker compose编排Laravel应用的方法

2020-06-17 06:48:39易采站长站整理

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.conf:/usr/local/etc/redis/redis.conf"
container_name: "oa-redis"

networks:
oa-network:
driver: bridge

这里定义了php-fpm、nignx、mysql、redis四个服务(如果需要其他服务,自行添加)。然后定义了一个公共的networks,这样容器内都可以很方便地进行通信。

比如nginx.conf中


server {
listen 80;
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 500 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;
}
}

这里与php-fpm的连接方式:php:9000

Dockerfile.php


FROM php:7.2-fpm
Run echo "nameserver 223.5.5.5" >> /etc/resolv.conf
&& echo "nameserver 223.6.6.6" >> /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

这是Php镜像构建,这里改了dns服务器,并安装了若干php扩展。

使用

启动

./start 启动所有服务

命令行


./bin/php -v

# Laravel artisan
./bin/php artisan

总结

具体可访问:https://github.com/rootrl/php-environment-with-docker

您可能感兴趣的文章:详解如何用docker安装laravel开发环境使用 Docker 搭建 Laravel 本地环境的教程详解详解用Docker搭建Laravel和Vue项目的开发环境Docker部署Laravel应用的实现示例Docker部署Laravel应用实现队列&任务调度利用Docker搭建Laravel开发环境的完整步骤