Dockerでの環境構築のメモ。
ディレクトリ構造
sample
├── htdocs
| └── index.php
├── php
| ├──php.ini
| └── Dockerfile
└── docker-compose.yml
docker-compose.yml
docker-compose.yml
version: '3.7'
services:
mysql:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 'password'
phpmyadmin:
depends_on:
- mysql
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: mysql
restart: always
ports:
- "8080:80"
php-apache:
build: ./php
volumes:
- ./htdocs:/var/www/html
restart: always
ports:
- "80:80"
depends_on:
- mysql
volumes:
db_data: {}
Dockerfile
--with-jpeg-dir でJPEGも有効になる。
Dockerfile
FROM php:8.1.1-apache
COPY ./php.ini /usr/local/etc/php/
RUN apt-get update \
&& apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
&& docker-php-ext-configure gd --with-jpeg-dir=/usr \
&& docker-php-ext-install pdo_mysql mysqli mbstring gd iconv
php.ini
php.ini
[Date]
date.timezone = "Asia/Tokyo"
[mbstring]
mbstring.internal_encoding = "UTF-8"
mbstring.language = "Japanese"
html.php
html.php
<?php
phpinfo();
起動
イメージのビルド
$ docker-compose build
イメージの確認
$ docker images
コンテナの起動
$ docker-compose up -d
動作確認
phpinfoにアクセスしてGDが有効になっているか確認
phpMyAdminにアクセス