0
0

More than 3 years have passed since last update.

簡易的なclearlinuxベースのlumen環境

Posted at
  • コンテナ環境で構築するPHPのベースイメージとして定番のphp-fpmがあるが容量の重さは否めない。
  • その対応策としてalpineという軽量ベースイメージを用いることも多いが、堅牢性やパフォーマンスの心配もある。
  • そこで今回は、堅牢性やパフォーマンスが高いと言われているclearlinuxをベースイメージにして、軽量FWのlaravel製のlumen環境を作成する。

環境

  • Mac OS X 10.15.6
  • Docker version 20.10.8
  • Docker Compose version v2.0.0-rc.1

手順

必要ファイル作成

  • 以下のコマンドを入力して、必要なファイルを作成する。
# 作業フォルダ作成 & 移動
mkdir work; cd $_
# docker file作成
touch Dockerfile docker-compose.yml .dockerignore
# nginxの設定ファイル作成
touch default.conf
  • 作成後、各ファイルの中身を以下のようにする。
Dockerfile
FROM clearlinux/php-fpm

RUN swupd bundle-add php-extras unzip \
    && rm -rf /var/lib/swupd/*

COPY --from=composer /usr/bin/composer /usr/bin/composer

WORKDIR /var/www/html/src
docker-compose.yml
version: "3"

services:
  web:
    image: nginx
    ports:
      - 8080:80
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf
      - ./src:/var/www/html/src
    restart: always
    depends_on:
      - php

  php:
    build: .
    volumes:
      - ./src:/var/www/html/src
  # db: 省略
.dockerignore
.git
Dockerfile
docker-compose.yml
default.conf
server {
    listen 80;
    root /var/www/html/src/public;

    location / {
        index  index.php index.html;
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
       fastcgi_pass   php:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include        fastcgi_params;
    }
}

イメージの起動及びプロジェクトの作成

  • 上記のファイル群作成後、下記のコマンドでイメージの起動を行う。
# イメージの起動
$ docker-compose up -d

# lumenプロジェクトの作成
$ docker-compose exec php composer create-project --prefer-dist laravel/lumen .

確認

  • 起動及びプロジェクト作成後、localhost:8080をアクセスして以下のようなバージョン情報が表示されれば完了。

image

まとめ

  • 容量は問題ないレベルで軽量化しており、パフォーマンスも安定している。
  • また最低限揃っており、swupdと合わせることにより記述も短い。
  • もう少し様子見をして今後を検討する。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0