Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Basile404's avatar

Using laravel/boost in a docker environment

Hi

I recently saw a video from Jeffrey Way about Boost, and thought: I will give it a try. I am also trying to move more towards Docker (not using Sail at the moment) as well.

The context

The way I have it set up right now is as follows:

  • Laravel 12 (livewire/blade components)
  • npm v22 & Vite 7

docker-compose.yml

Dockerfile

The issue

My container is being build without errors, but once I open my application in the browser I get a laravel error saying Class "Laravel\Boost\BoostServiceProvider" not found. For some reason I am not able to get the boost package correctly set up through my Dockerfile.

If I go into my docker container's console, I am able to install it manually and the problem goes away, but it doesn't feel right to have to manually set it up.

My question

  • Does my build need to have boost at all? as it's more likely I will be using it on my local machine anyway.
  • If it's something I should include in my build, how do I set it up so it installs with the Dockerfile?
0 likes
6 replies
LaryAI's avatar
Level 58

Absolutely, let's break down the problem and solution step by step!

1. Why is BoostServiceProvider Not Found?

This error (Class "Laravel\Boost\BoostServiceProvider" not found) means the laravel/boost package was not installed during the image build process. You mentioned that installing it manually works – that indicates the Docker build flow is missing either:

  • The package in composer.json
  • Or not running composer install after it's added.

2. Should You Ship Boost in Your Container?

Production

  • No, usually not. Laravel Boost is designed to optimize the local development experience; it is not needed nor recommended for production builds.
  • Only add it for local/dev containers.

Local Development with Docker

  • Yes, if you want Boost's dev features inside the container.
    If you develop inside the container, Boost improves the experience in the same way as running it locally.

3. How to Include Boost in Your Docker Build

Step 1: Add Boost to Composer (Locally)

On your local machine, run:

composer require laravel/boost --dev

This updates composer.json and composer.lock.

Step 2: Make Sure You Copy the Full composer.json Into the Image

Many Dockerfiles only copy composer.json/composer.lock first for caching. If you don’t rebuild those layers after changing them, Docker will NOT pick up the change.

Before:

COPY composer.json composer.lock ./
RUN composer install --no-dev --optimize-autoloader --no-scripts --no-interaction

The above line installs without dev dependencies (so boost is never installed).

Solution:

For a local/development build, don’t use --no-dev! (Or: add a build ARG to let you choose.)

# For development images:
RUN composer install --no-interaction --no-scripts

# For production images:
# RUN composer install --no-interaction --no-scripts --optimize-autoloader --no-dev

Step 3: Rebuild Your Docker Image

Always rebuild (not just start) after modifying PHP dependencies or Dockerfile!

docker-compose build --no-cache
docker-compose up

4. Example Dockerfile changes

Key changes:

  • Remove --no-dev if you want dev packages.
  • Ensure composer files are fresh.
  • Run composer install in the right mode.
COPY composer.json composer.lock ./
RUN composer install --no-interaction --no-scripts

If you want to control between dev and production builds (optional):

ARG ENVIRONMENT=development
COPY composer.json composer.lock ./
RUN if [ "$ENVIRONMENT" = "production" ]; then \
        composer install --no-interaction --no-scripts --optimize-autoloader --no-dev; \
    else \
        composer install --no-interaction --no-scripts; \
    fi

Then build with:

docker build --build-arg ENVIRONMENT=development -t appname-app-local .

5. Summary Checklist

  • Add laravel/boost to composer.json with composer require laravel/boost --dev
  • DON’T use --no-dev in composer command for local/dev Docker builds.
  • Copy updated composer.json/composer.lock before running composer install.
  • Rebuild your Docker image with --no-cache.

6. Optional: Local Only Install

If you want Boost available only for local development, do NOT put it in images used in production.


References


Final Example for Local Dev:

COPY composer.json composer.lock ./
RUN composer install --no-interaction --no-scripts

And make sure laravel/boost is in require-dev in composer.json.


Conclusion:
You need to allow dev dependencies in your local build’s composer install step and ensure that you copy the new composer files in. Rebuild and you should be all set!

Let me know if you need help adjusting your Dockerfile for multi-stage builds or local-vs-production environments!

Basile404's avatar

The package is installed, it's just not being set up with php artisan boost:install which requires input to install the provider.

I have tried the no-interaction in my composer install command, but it does not fix this problem.

Also, this docker environment is a local test environment, I would very much want to keep my other dev dependencies. like the debugbar for example

Basile404's avatar

Removing the --no-dev in my composer install fixed the problem.

Alternatively, I am now curious, once I got to a staging/prod environment that runs on docker as well.. What would be the solution as I would need to use the --no-dev argument in my build process.

martinbean's avatar

Removing the --no-dev in my composer install fixed the problem.

@basile404 But if you’re running the application locally, then it is dev, and you therefore do want to install dev dependencies?

tommmoe's avatar

Only way around it I've found is to just install it on the container whenever I need it, hopefully someone comes along with a better solution..

JKL's avatar

The solution to the dev, stage and prod scenario would be to make diffrent Dockerfiles depending on the enviroment.

Please or to participate in this conversation.