1.前期准备

1.1 配置docker镜像加速器

配置docker镜像加速器,修改docker配置文件.

image.png

1.2 新增registry-mirrors项

{
"experimental": false,
"debug": true,
"registry-mirrors": [
"https://xxx.mirror.aliyuncs.com" // 阿里云免费docker镜像加速
]
}

1.3 免费申请阿里云docker镜像加速

免费申请阿里云docker镜像加速 点击申请

aa.png

2.开始安装

2.1 步骤一: 下载代码

# 克隆代码
$ git clone https://github.com/52lu/docker-compose-server.git

# 查看代码目录
$ docker-compose-server git:(main) ls
README.md docker-compose.yml env-example kibana logstash mongo nginx rabbitmq solr
bin elasticsearch grafana logs memcached mysql php-fpm redis workspace

2.2 步骤二: 配置文件

  • 执行 cp env-example .env

  • 修改配置文件内容

    APP_CODE_PATH_HOST---> 你PHP项目所在的上级目录文件
    DATA_PATH_HOST ---> 数据持久化位置,比如Mysql/Redis/Mongo产生的物理文件
    DOCKER_HOST_IP ---> 修改成本地的IP(不修改的话,会出现无法捕获到断点情况)

    2.3 步骤三: 配置nginx

配置目录: docker_php_env/nginx/sites/example.conf

server {
charset utf-8;
listen 80;
# 本地域名,xdebug会用到
server_name saaspro.com;
# 容器中的目录路径
root /var/www/saaspro/web;
error_page 404 /404.html ;
index index.php index.html;
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
# uncomment to avoid processing of calls to non-existing static files by Yii
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}
# error_page 404 /404.html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-upstream;
# fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
location ~ /\.(ht|svn|git) {
deny all;
}
}

2.4 步骤四: 启动脚本

1. 脚本说明

文件位置: docker_php_env/bin/restart-php.sh

docker-compose down # 关闭所有服务
docker-compose build nginx php-fpm workspace # 下载nginx、php-fpm、workspace 镜像
docker-compose up -d nginx # 启动nginx镜像,同时会启动php-fpm、workspace镜像
docker-compose ps # 查看启动服务情况

2. 启动脚本

# 赋值权限
chmod 777 bin/*

# 启动
./bin/restart-php.sh

3. 启动结果

$ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
env_docker-in-docker_1 dockerd-entrypoint.sh Up 2375/tcp, 2376/tcp
env_nginx_1 /docker-entrypoint.sh /bin ... Up 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp
env_php-fpm_1 docker-php-entrypoint php-fpm Up 9000/tcp
env_workspace_1 /sbin/my_init Up 0.0.0.0:2223->22/tcp, 0.0.0.0:8080->8010/tcp, 0.0.0.0:8081->8011/tcp, 0.0.0.0:8082->8012/tcp, 0.0.0.0:8083->8013/tcp, 0.0.0.0:8084->8014/tcp, 0.0.0.0:8085->8015/tcp,
0.0.0.0:8086->8016/tcp, 0.0.0.0:8087->8017/tcp, 0.0.0.0:8088->8018/tcp, 0.0.0.0:8089->8019/tcp, 0.0.0.0:8090->8020/tcp

2.5 步骤五: 配置PHPStorm

1.png

2.png

3.png

4.png

2.6 步骤六: 修改本地hosts文件

## 打开hosts文件
sudo vim /etc/hosts

# 你nginx中具体配置的server_name
127.0.0.1 saaspro.com

3. debug效果

WX20200619-122659@2x.png

4. 其他文档

laradock开源github地址

中文文档