Docker
How to Docker Container for Laravel 11 App with php 8.2
December 14, 2024
0
,

Suppose you are buiding a project that you want to provide Docker Container as well so that other team members can use the same project using same machine environment like your product machine:

First I am creating laravel app named MyApp::
# composer create-project laravel/laravel MyApp

Create a Folder docker-setup, copy the folder MyApp contents to laravel11-docker/src/
Not in the folder but top of that folder, write docker-compose.yaml, Dockerfile:

Dockerfile: [github link:  https://github.com/arzerin/docker-laravel/blob/main/Dockerfile]

docker-compose.yaml: [github link: https://github.com/arzerin/docker-laravel]

Key Points:

  1. PHP Version: The Dockerfile uses php:8.2.10 (as per your request).
  2. Dependencies: The required PHP extensions (pdo, pdo_pgsql, pdo_mysql) are installed.
  3. Composer: Composer is globally installed for dependency management.
  4. Laravel App: The app is mounted into the /app directory in the container.
  5. PostgreSQL Database: The docker-compose.yml includes a PostgreSQL service (db), which is configured with environment variables for the database.
  6. Ports: The application is accessible at localhost:8000 on your machine.

How to Use:

  1. Place the Dockerfile and docker-compose.yml at the root of your project.
  2. Ensure your Laravel project is located at laravel11-docker/src.
  3. Run the following command to build and start the containers:docker-compose up –build
  4. You should now be able to access your Laravel application at http://localhost:8000.
  5. To use any command or file in container: docker exec -it laravel-app bash
    In the above line “laravel-app ” is the container name. You will be logged in that folder where you can run laravel basic command like php artisan serve etc

github link: https://github.com/arzerin/docker-laravel

About author

ZERIN

CEO & Founder (BdBooking.com - Online Hotel Booking System), CEO & Founder (TaskGum.com - Task Managment Software), CEO & Founder (InnKeyPro.com - Hotel ERP), Software Engineer & Solution Architect

There are 0 comments

Leave a Reply

Your email address will not be published. Required fields are marked *