services:
  php:
    image: php:7.4-fpm-alpine
    user: "101:101"
    volumes:
      - ./www:/usr/share/nginx/html
      # 关键：覆盖fpm监听配置
      - ./www/php-fpm/www.conf:/usr/local/etc/php-fpm.d/www.conf
    # 直接apk安装mysqli，不编译，避免gcc全家桶
    command: >
      sh -c "apk add --no-cache php7.4-mysqli && php-fpm"

  nginx:
    image: nginx:stable-alpine
    ports:
      - "8080:80"
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
      - ./www:/usr/share/nginx/html
    depends_on:
      - php
    # alpine自带wget等待php端口就绪
    command: ["/bin/sh", "-c", "until wget -q -T1 php:9000; do echo '等待php-fpm就绪...'; sleep 1; done; nginx -g 'daemon off;'"]
