Dockerize Your Laravel Application

Share this post on:

How to Install Laravel with Docker

Before we dive into the installation steps, make sure you have the necessary system requirements and Windows edition to run Docker Desktop. Here’s a simplified guide to get Laravel up and running with Docker.

System Requirements

  • Windows 11 (64-bit): Home or Pro version 21H2 or higher, or Enterprise or Education version 21H2 or higher.
  • Windows 10 (64-bit): Home or Pro 21H2 (build 19045) or higher, or Enterprise or Education 21H2 (build 19045) or higher.
  • Ensure WSL 2 (Windows Subsystem for Linux 2) is enabled on Windows. Refer to Microsoft’s documentation for instructions.

Hardware Prerequisites

For Windows 10 or 11, you’ll need:

  • 64-bit processor with Second Level Address Translation (SLAT)
  • 4GB system RAM
  • BIOS-level hardware virtualization support enabled

Important Note

Running Windows containers requires Windows 10 or 11 Professional or Enterprise edition. Windows Home or Education editions only support Linux containers.

Installation Steps

  1. Download Docker Desktop for Windows from their official website.
  2. Run the installer by double-clicking on “Docker Desktop Installer.exe.”
  3. During installation, select the “Use WSL 2 instead of Hyper-V” option if available.
    • Note: If your system supports only one option, you won’t have a choice in the backend.
  4. Follow the installation wizard’s instructions to authorize the installer and complete the process.
  5. After successful installation, select “Close.” Docker will ask you to log out and back into your Windows session or restart your machine to finish the installation.

Starting Docker Desktop

After the restart:

  1. Start Docker Desktop by searching for it in the start menu.
  2. The first time you run Docker, it may take a few minutes to configure itself.
  3. Open a command prompt or PowerShell window.
  4. Run the command docker --version to ensure Docker is installed and running.

Setting Up Laravel with Docker

Dockerfile

Create a Dockerfile in your Laravel project’s root directory with the following content:

docker-compose.yml

Create a docker-compose.yml file in your Laravel project’s root directory:

Running Docker Containers

  1. Navigate to your Laravel project’s base directory in the command prompt.
  2. Execute docker-compose build to build the Docker containers.
  3. Launch the application with docker-compose up.
  4. Access the Docker container with docker exec -it laravel-docker bash. Replace “laravel-docker” with your container’s name if different.

Install Laravel and Configure Database

  1. Install Laravel using the command: composer create-project laravel/laravel .
  2. Once Laravel is installed, execute the exit command.

Modify the .env File

Update the database connection details in the .env file with these settings:

Execute Migrations

Run the migrations using the following command:

Now, your Laravel project should be accessible at http://localhost:9000/public/, and you can manage your database with PHPMyAdmin at http://localhost:9001/. Enjoy developing with Laravel and Docker!

Share this post on:

Author: Piyush Solanki

Piyush is a seasoned PHP Tech Lead with 10+ years of experience architecting and delivering scalable web and mobile backend solutions for global brands and fast-growing SMEs. He specializes in PHP, MySQL, CodeIgniter, WordPress, and custom API development, helping businesses modernize legacy systems and launch secure, high-performance digital products.

He collaborates closely with mobile teams building Android & iOS apps , developing RESTful APIs, cloud integrations, and secure payment systems using platforms like Stripe, AWS S3, and OTP/SMS gateways. His work extends across CMS customization, microservices-ready backend architectures, and smooth product deployments across Linux and cloud-based environments.

Piyush also has a strong understanding of modern front-end technologies such as React and TypeScript, enabling him to contribute to full-stack development workflows and advanced admin panels. With a successful delivery track record in the UK market and experience building digital products for sectors like finance, hospitality, retail, consulting, and food services, Piyush is passionate about helping SMEs scale technology teams, improve operational efficiency, and accelerate innovation through backend excellence and digital tools.

View all posts by Piyush Solanki >