leadsdoit/lara-php

By leadsdoit

Updated 6 months ago

Images for Laravel with PostgreSQL

Image
Languages & frameworks
Developer tools
Web servers
0

2.9K

leadsdoit/lara-php repository overview

leadsdoit/lara-php

This image is based on php:${PHP_VER}-fpm for working with the Laravel framework.

Published on Docker Hub

Usage example

Dev
services:
    php-dev:
        image: leadsdoit/lara-php:8.4-dev
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        container_name: docker_php_dev
        restart: always
        volumes:
            - ./:/app
            # - "./script/php/php.ini:/usr/local/etc/php/conf.d/88-conf.ini:ro"
            # - "./script/php/xdebug.ini:/usr/local/etc/php/conf.d/99-xdebug.ini:ro"
        environment:
            PHP_IDE_CONFIG: "serverName=docker_php_dev"
            IGNITION_LOCAL_SITES_PATH: '${PWD}'
            CONTAINER_ROLE: "app"
            LARAVEL_SAIL: 1
            # XDEBUG_MODE: "off"
        ports:
            - "127.0.0.1:9002:9000"
alias sail='sh $([ -f sail ] && echo sail || echo vendor/bin/sail)'

sail up -d --build

sail composer install

Prod

Dockerfile

FROM leadsdoit/lara-php:8.4

WORKDIR /app
COPY . .
RUN [ -d /app/vendor ] && rm -r /app/vendor || echo "Directory /app/vendor does not exist"
RUN rm -r /app/docker

RUN chown -R www-data:www-data /app  \
    && chmod -R 755 /app/storage

RUN composer install --optimize-autoloader  --no-dev

docker-compose.yml

x-common-app-settings: &common-app-settings
    image: leadsdoit/lara-php:8.4
    restart: always
    working_dir: /app
    networks:
        - lara-network

services:
    app_php:
        <<: *common-app-settings
        container_name: lara_app_php
        environment:
            CONTAINER_ROLE: "app"
        depends_on:
            db:
                condition: service_healthy
            redis:
                condition: service_healthy

    app_queue:
        <<: *common-app-settings
        container_name: lara_app_queue
        environment:
            CONTAINER_ROLE: "queue"
        depends_on:
            - app_php

    app_cron:
        <<: *common-app-settings
        container_name: lara_app_cron
        environment:
            CONTAINER_ROLE: "cron"
        depends_on:
            - app_php

Extensions

composer is installed in the image.

Also included:

  • zip
  • opcache
  • intl
  • pcntl
  • sockets
  • bcmath
  • redis
  • soap
  • pgsql
  • pdo_pgsql

The image includes the install-php-extensions script. If you need to install more extensions, add the install-php-extensions call in your Dockerfile.

FROM leadsdoit/lara-php:8.4-dev as phpdev

RUN install-php-extensions \
    mysqli \
    pdo_mysql

Available extensions

RUN install-php-extensions <extensions separated by spaces>

Roles

The image can run in the following roles:

  • app
  • queue
  • cron

Select the role via the CONTAINER_ROLE environment variable. Default role is app.

The queue role supports:

  • WORK_ON_QUEUES - which queues to process, default = height,default,low
  • QUEUE_CONNECTION - connection driver; if not set, uses the default
  • QUEUE_TIMEOUT - default timeout; if not set, 60 seconds
  • QUEUE_TRIES - retry count; if not set, 1

Configuration

If you need custom configuration, the image includes the following files you can override.

PHP

/usr/local/etc/php/conf.d/00-conf.ini

Xdebug

/usr/local/etc/php/conf.d/01-xdebug.ini

Cron

/etc/cron.d/app_cron

Entrypoint script

/usr/local/bin/entrypoint

Development mode

The -dev image includes Xdebug.

Minimal config at: /usr/local/etc/php/conf.d/01-xdebug.ini

Additional utilities in the dev image

The dev image includes extra CLI tools for local development:

  • git — version control inside the container
  • iproute2 — provides ss for checking open ports/sockets
  • nano — quick edits for configs and small files
  • htop — interactive process viewer
Environment variables

You can control the modes via:

  • XDEBUG_MODE - enables debug mode; default is on, set off to disable
  • LARAVEL_SAIL - enables Sail mode; default is 1, set 0 to disable
Sail

More details here

The image adds a sail user.

For Sail mode to work correctly, add this to your .env file: APP_SERVICE=<container_name>

Scripts

Dev App

This script is available only in the DEV image.

  • If using docker

    docker exec -it <container_name> dev-app

  • If using docker compose

    docker compose exec <service_name> dev-app

When you run the script, it shows a menu:

Select a category:
1. node
2. lara
3. Exit
Node

This category lets you install a specific Node.js version. Inside the container, it installs NVM, then installs the requested version and sets it as default.

You can install Node.js 22 directly:

docker compose exec <service_name> dev-app node install 22

After installation, Node.js is available for external calls:

docker compose exec <service_name> node -v

Lara

This category lets you create a new Laravel app inside the container.

Create a minimal docker-compose.yml in your project folder:

services:
    app_php:
        image: leadsdoit/lara-php:8.3-dev
        restart: always
        volumes:
            - ./:/app
        environment:
            CONTAINER_ROLE: "app"

Run:

docker compose exec <service_name> dev-app lara install

After that, a new app is created in a temporary folder inside the container. You will answer the Laravel initialization questions, and then all files are moved into /app.

After copying, you should change ownership to your user:

sudo chown -R <your_user>:<your_user> .

This command will fail if a project already exists.

Tag summary

Content type

Image

Digest

sha256:239a87deb

Size

230.9 MB

Last updated

6 months ago

docker pull leadsdoit/lara-php:dev