├── docker-compose.yml
├── nginx
│ ├── default.conf
│ └── src
│ └── index.html
├── php-fpm
│ ├── Dockerfile
│ └── src
│ └── index.php
└── src
└── nginx
version: '3'
services:
nginx:
image: nginx:latest
ports:
- 8080:80
volumes:
- ./nginx/src:/usr/share/nginx/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php-fpm
php-fpm:
build:
context: .
dockerfile: ./php-fpm/Dockerfile
volumes:
- ./php-fpm/src:/var/www/html
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /var/www/html;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
以下の内容ならばdocker-compose.yml
のimageプロパティに直接指定すればよいが、buildプロパティの例としてDockerfileに記載する。
FROM php:7.4-fpm
$ docker-compose build
$ docker image ls
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx-php-fpm_php-fpm latest eb029ced96bd 12 days ago 443MB
php 7.4-fpm eb029ced96bd 12 days ago 443MB
nginx latest fa5269854a5e 12 days ago 142MB
php
サービスのイメージ名は以下の命名規則に従う。
ディレクトリ名_サービス名
$ docker-compose up -d
Creating network "nginx-php-fpm_default" with the default driver
Creating nginx-php-fpm_php-fpm_1 ... done
Creating nginx-php-fpm_nginx_1 ... done
$ docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e4b7528db18 nginx:latest "/docker-entrypoint.…" About a minute ago Up About a minute 0.0.0.0:8080->80/tcp nginx-php-fpm_nginx_1
403881af8722 nginx-php-fpm_php-fpm "docker-php-entrypoi…" About a minute ago Up About a minute 9000/tcp nginx-php-fpm_php-fpm_1
docker-php-entrypointの場所は以下のファイルを参考にする。
https://github.com/docker-library/php/tree/master/8.1/buster/fpm