因为我这里环境是PHP+Nginx+Pgsql 所以如果大家有需要的可以自己研究下更改下配置
直接上配置文件
docker-compose.yml
version: '3.1'
services:
db:
image: "postgres:latest"
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: "postgres"
PGDATA: /var/lib/postgresql/data/pgdata
redis:
image: "redis:latest"
ports:
- "6379:6379"
php:
build:
context: ./
dockerfile: Dockerfile
image: php:7.4-fpm-xdebug
ports:
- "9000:9000"
depends_on:
- db
- redis
links:
- db
- redis
volumes:
- ./../:/usr/share/nginx/html
- ./xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
nginx:
image: "nginx:latest"
ports:
- "80:80"
depends_on:
- php
links:
- php
volumes:
- ./conf.d/:/etc/nginx/conf.d
- ./../:/usr/share/nginx/html
volumes:
pgdata:
external:
name: pgdata
Dockerfile
FROM php:7.4-fpm
# 2.9.0 的安装不能识别命名空间
RUN apt-get update && apt-get install -y libpq-dev \
&& docker-php-ext-install pgsql \
&& docker-php-ext-install pdo_pgsql \
&& pecl install xdebug-2.8.1 \
&& pecl install redis-5.2.1 \
&& docker-php-ext-enable xdebug redis \
&& curl -o composer https://mirrors.aliyun.com/composer/composer.phar \
&& mv composer /usr/bin/composer \
&& chmod a+x /usr/bin/composer \
&& composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ \
&& composer self-update
COPY ./xdebug.ini $PHP_INI_DIR/conf.d/
RUN cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
xdebug配置文件
[XDebug]
; debug开关 1开 0 关
xdebug.enable=1
xdebug.remote_enable=1
; 这个是约定的调试码,需要在phpstorm里面设定
xdebug.idekey=PHPSTORM
; 这个是自己的主机ip
xdebug.remote_host=docker.for.mac.localhost
xdebug.remote_handler="dbgp"
; IDE与此处端口保持一致
xdebug.remote_port=9001
xdebug.remote_log="/tmp/xdebug_php73.log"
nginx的配置文件,在conf.d目录下
server {
listen 80;
root /usr/share/nginx/html/public;
index index.php index.html;
server_name localhost
charset utf-8;
# location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|js)$ {
# access_log off;
# expires max;
# }
location / {
try_files $uri $uri/ /index.php?$args;
}
client_max_body_size 32m;
# There is a VirtualBox bug related to sendfile that can lead to
# corrupted files, if not turned-off
# sendfile off;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/public/$fastcgi_script_name;
fastcgi_pass php-fpm;
fastcgi_index index.php;
include fastcgi_params;
## Cache
# fastcgi_pass_header Cookie; # fill cookie valiables, $cookie_phpsessid for exmaple
# fastcgi_ignore_headers Cache-Control Expires Set-Cookie; # Use it with caution because it is cause SEO problems
# fastcgi_cache_key "$request_method|$server_addr:$server_port$request_uri|$cookie_phpsessid"; # generating unique key
# fastcgi_cache fastcgi_cache; # use fastcgi_cache keys_zone
# fastcgi_cache_path /tmp/nginx/ levels=1:2 keys_zone=fastcgi_cache:16m max_size=256m inactive=1d;
# fastcgi_temp_path /tmp/nginx/temp 1 2; # temp files folder
# fastcgi_cache_use_stale updating error timeout invalid_header http_500; # show cached page if error (even if it is outdated)
# fastcgi_cache_valid 200 404 10s; # cache lifetime for 200 404;
# or fastcgi_cache_valid any 10s; # use it if you want to cache any responses
}
}
## PHP-FPM Servers ##
upstream php-fpm {
server php:9000;
}
文件结构图
码云链接
https://gitee.com/f5/codes/tzyjbi50nx87oqcvsu4p357#0-tsina-1-474-397232819ff9a47a7b7e80a40613cfe1