Laravel 12 Queue Jobs Tutorial with Docker (Step-by-Step from Scratch)
A complete guide to setting up Laravel 12 queues with Docker, jobs, and background processing.
Before we start creating jobs in Laravel 12, let's set up a local development environment using Docker. This approach allows us to run Laravel, MySQL, and phpMyAdmin in isolated containers without installing them directly on our machine.
For this tutorial, we'll use three services:
- app – Runs our Laravel application
- mysql – Stores our application data
- phpMyAdmin – Provides a web interface for managing the database
Create a docker-compose.yml file in the root of your project and add the following configuration:
Now that we have defined our application services, we need to create a Docker image for the Laravel application.
Create a Dockerfile in the root of your project and add the following configuration:
This image uses PHP 8.3 and installs the extensions required by Laravel, including MySQL support, file handling, image processing, and queue-related functionality. It also installs Composer so we can manage our project's dependencies directly from within the container.
Now that both docker-compose.yml and Dockerfile are ready, we need to build our Docker images and start the containers.
Build the Docker containers
Run the following command to build the application image:
docker compose build
This command reads the Dockerfile and installs all required dependencies inside the image, including PHP extensions and Composer.
Start the containers
Once the build is complete, start all services using:
docker compose up
Installing Laravel 12 inside Docker
Now that our Docker containers are running, the next step is to install Laravel 12 inside the application container.
Since we are using Docker Desktop, everything runs inside our app container.
Inside the container, run the following command:
composer create-project laravel/laravel:^12.0 jobs-app
We specify :^12.0 to ensure we are installing Laravel 12 explicitly.
This tells Composer to install Laravel in the current directory (/var/www/jobs-app), which is already mapped to our local project folder.
Verify installation
After installation completes, your project structure should look like this:
app/
bootstrap/
config/
database/
routes/
artisan
At this point, Laravel 12 is successfully installed inside our Docker environment.
Open the application
Visit:
http://localhost:8000/jobs-app/public/index.php
You should now see the Laravel welcome page running from Docker.
Update .env Settings
Also change
Change it to
Run Artisan Migration Commands
Because Laravel needs this table:
jobs table stores jobs that are waiting to be executed.Think of it like Jobs in line, waiting for the worker to pick them up.
failed_jobs table stores jobs that crashed or failed permanently. Think of it as Jobs that could not be processed successfully.
Creating a Controller and Route in Laravel 12
Now that Laravel is installed inside our Docker container, we will create a controller and a route to trigger our job later.
This will act as the entry point where we dispatch our background job.
Inside the Docker container, under jobs-app and run:
php artisan make:controller TransactionController
This will create:
app/Http/Controllers/ProductController.php
Define the route
Open routes/web.php and add:
Create a Job using Laravel Artisan Command
php artisan make:job StoreProductJob
You will see a file in app/Http/Jobs
Dispatching and Running Jobs in Laravel 12
Now that we have created our job (StoreProductJob), let’s understand how to dispatch and execute it.
In Laravel, dispatching a job does not run it immediately. Instead, it pushes the job into a queue, and a background worker processes it.
Run this url
When this method is called:
- The job is added to the queue
- It is stored in the jobs table (if using database queue)
- It does NOT execute immediately
Check the image below
Run the Queue Worker
To actually process the job, we need to start the queue worker.
Inside your Docker container, run:
This command continuously listens for new jobs and executes them.