maya's blog

About programming, aws and ubuntu

php-fpm, nginx, docker-compose

github.com

主要ファイル

docker-compose.yml

version: '3'
services:
  nginx:
    image: nginx:1.15.7-alpine
    links:
      - php-fpm
    ports:
      - "8080:80"
    volumes:
      - ./src:/var/www/html
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./conf.d:/etc/nginx/conf.d
  php-fpm:
    image: php:7.2.12-fpm-stretch
    ports:
      - "9000:9000"
    volumes:
      - ./src:/var/www/html

/etc/nginx/conf.d/php-fpm.conf

server {
    listen 80;
    root /var/www/html;
    index index.php;

    location ~* \.php$ {
        fastcgi_pass    php-fpm:9000;
        include         fastcgi.conf;
    }
}

docker-compose up時に何をしているのか?

  • php-fpm, nginxコンテナを立ち上げ
  • nginxコンテナ立ち上げ時にnginxの設定ファイルnginx.conf, conf.d/php-fpm.conf/etc/nginx/nginx.conf, /etc/nginx/conf.dに同期
  • host osの./srcphp-fpmコンテナの/var/www/html, nginxコンテナの/var/www/htmlに同期

多分これが一番小さい設定だと思います

phpinfo
phpinfo