Skip to content

RinMinase/laravel-docker-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

32 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Laravel Logo

Introduction / Motivation of this project

I'm sick of other extremely complicated and lengthy guides and tutorials on how to create a Dockerized Laravel (see here, here, here and here), so I created one myself. Using this is as simple as cloning or downloading the whole template then running docker-compose up -d, setup can be finished in more-or-less 5-10 minutes.

Using the template

Using Git template

  1. Click Use this template then Create a new repository
  2. Clone your newly created repository
  3. Copy the env file by running cp .env.example .env
  4. Create and run the docker containers by docker-compose up -d
  5. Navigate in the created container docker exec -it php sh
  6. Run the commands below to start your Laravel application
composer install
php artisan key:generate
php artisan migrate:fresh --seed

Using Git clone

  1. Clone the repository by running git clone git@github.com:RinMinase/laravel-docker-template.git
  2. Remove instances of the original repository on your project
  • Open your terminal and run these commands below:
    • git remote remove origin
    • rm -rf .git/
    • git init
  1. Copy the env file by running cp .env.example .env
  2. Create and run the docker containers by docker-compose up -d
  3. Navigate in the created container docker exec -it php sh
  4. Run the commands below to start your Laravel application
composer install
php artisan key:generate
php artisan migrate:fresh --seed

Downloading the repository

  1. Download the repository as a zip file
  2. Copy the env file by running cp .env.example .env
  3. Create and run the docker containers by docker-compose up -d
  4. Navigate in the created container docker exec -it php sh
  5. Run the commands below to start your Laravel application
composer install
php artisan key:generate
php artisan migrate:fresh --seed

Default Values

This project contains 3 docker containers, all of which uses the official docker images in Alpine linux

  • php (which houses your source code)
    • container name: php
  • nginx (which houses the webserver that runs your code in a browser)
    • container name: webserver
  • db (which contains the database of your project)
    • container name: database
    • by default this uses PostgreSQL, but feel free to change it to your desired database

The database by default uses these default parameters to let you get started without even touching any configuration settings

  • DB_DATABASE or your default database name: laravel
  • DB_USERNAME or your default database username: postgres
  • DB_PASSWORD or your default database password: postgres

Job / Commands / Schedule updates and restarting the supervisor

Return to the table of contents

In cases there are any updates to:

  • Jobs (found on app/Jobs)
  • Commands (found on app/Commands)
  • Schedules (found on bootstrap/app.php under withSchedule)

Please run the following:

  1. Navigate inside the php docker container [how]

  2. Run the command to restart the group (queue-worker and schedule-worker)

    supervisorctl restart worker:

Managing the supervisor

Return to the table of contents

This application runs supervisor on the php container. Supervisor runs these tasks:

Task Name Group Command Description
php-fpm - php-fpm Runs FastCGI Process Manager
queue-worker worker php artisan queue:work Runs Laravel's Queue worker
schedule-worker worker php artisan schedule:work Runs Laravel's Schedule worker

To manage the supervisor the commands below can be used:

Command Description
supervisorctl reread Re-reads changes in supervisor config files
supervisorctl update Updates supervisor with changes after reread
supervisorctl status Check status of all running tasks
supervisorctl start Starts the task
supervisorctl stop Stops the task
supervisorctl restart Restarts the task

Please note: Supervisor logs are kept in ./docker/logs/supervisor.log

FAQ

How to update PHP / caddy / PostgreSQL?

Why use official images?

Other tutorials or guides uses customized images (see here for the guide -- actual line of code), these images are so hard to update manually compared to just editing a value then rebuilding the whole container again, see the question above on how to update each docker container.

Why use alpine linux?

Alpine linux is very lightweight and secure enough. Since the image used is lightweight, you can quickly download it compared to fully-fledged linux distros such as Ubuntu. (Some references for these: here and here).

Nonetheless, it also has its downsides, (references here and here) I've even encountered a few of them, these are:

  • using other package managers aside from apk
  • some libraries which you may possibly use are not present such as glibc since alpine uses musl-libc and requires a sad and annoying workaround for it to work

Why use (or migrated) to caddy instead of nginx?

Caddy is often preferred over Nginx for its simplicity and modern design. Unlike Nginx, Caddy automatically handles HTTPS with free TLS certificates via Let’s Encrypt, removing the need for manual certificate setup or cron jobs (although this is not used in this repository as it was deemed unnecessary).

Additionally, its configuration syntax is way cleaner and extremely easier to understand, making it ideal for quick deployments and maintainable setups.

Regardless, if you do prefer nginx, please refer to the previous setup under this commit:

The files needed for it is likewise under ./docker/nginx-backup/* for the time being. The docker-compose setup is likewise commented as well for now.

Why use static versions for docker containers?

Why not? A variable version might mean that it works on my machine but not on yours because yours has a different (possibly newer) version than mine (references here and here).

About

πŸ“¦πŸž An extremely simple and lightweight Laravel Docker Template

Topics

Resources

Stars

Watchers

Forks

Contributors