bigmac-jp blog

web開発関連のメモ

ざっくりDocker その4

ざっくりDockerめも

nginx+php-fpm実行環境をさくっと作成。

ディレクトリ構成
.
├── docker-compose.yml
├── nginx
│   ├── Dockerfile
│   └── site.conf
└── php
    ├── Dockerfile
    └── src
        └── index.php
nginx

./nginx/Dockerfile

FROM nginx:latest
COPY ./site.conf /etc/nginx/conf.d/default.conf

./nginx/site.conf

server {
    index index.php index.html;
    server_name localhost;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}
php-fpm

./php/Dockerfile

FROM php:7-fpm

./php/src/index.php

<?php
echo phpinfo();
docker-compose.yml
version: '3'
services:
  web:
      build: ./nginx
      ports:
          - "8080:80"
      depends_on:
          - php
  php:
      build: ./php
      volumes:
      - ./php/src:/var/www/html
docker-compose build
$ docker-compose up --build -d

localhost:8080にブラウザでアクセスする。