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 installafter 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-devif you want dev packages. - Ensure composer files are fresh.
- Run
composer installin 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/boosttocomposer.jsonwithcomposer require laravel/boost --dev - DON’T use
--no-devin composer command for local/dev Docker builds. - Copy updated
composer.json/composer.lockbefore runningcomposer 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!