Skip to content

Stolz/laravel-docker-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Docker Stack

Skeleton for creating a multi-container Docker application based on Laravel framework.

For use in development environment only. Not suitable for use in production environment!.

The stack is created using Docker Compose and consist of the following services:

Features

  • Containers are based on Alpine Linux which makes them slim and fast.
  • Source code and server configuration files are mounted via Docker volumes so changes are reflected immediately, without having to rebuild the containers.
  • Database persisted data is also mounted via Docker volume so changes are not lost after rebuilding the containers.
  • Dependencies are managed using PHP Composer official Docker image to keep all the tools inside Docker land.
  • All services are run by the same UID:GID (1000:1000) to prevent permission problems between containers.
  • Communication between Nginx and PHP-FPM using UNIX sockets instead of TCP for better performance.
  • Communication between Redis and PHP using PhpRedis PHP extension for better performance.
  • Supervisor is used to automatically run Laravel queue workers.

Requirement

To prevent permission problems ensure all files and directories are owned by user:group 1000:1000.

Installation

Get the application skeleton

git clone git@github.com:Stolz/laravel-docker-stack.git my-laravel-project && cd my-laravel-project

Install your Laravel flavor

git clone git@github.com:laravel/laravel
docker run --rm -it --user 1000:1000 -v $(pwd)/laravel:/app -v $(pwd)/composer:/tmp composer install

Start the services

docker-compose up

Configuration

Configure environment following standard Laravel instructions:

cp laravel/.env.example laravel/.env
$EDITOR laravel/.env

To use Postgres database with the default user set these values ...

DB_CONNECTION=pgsql
DB_HOST=postgres
DB_PORT=5432
DB_DATABASE=postgres
DB_USERNAME=postgres
DB_PASSWORD=secret

... but since postgres is a privileged account you should consider creating a dedicated user instead. If you do so, don't forget to also update the service configuration in docker-compose.yml file.

To use Redis, first you need to edit config/database.php file to use PhpRedis client ...

'client' => env('REDIS_CLIENT', 'phpredis'),

... and then you can use these values in your .env file

BROADCAST_DRIVER=redis
CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
REDIS_CLIENT=phpredis
REDIS_HOST=redis
SESSION_DRIVER=redis

Artisan

You can run Artisan directly from the host. For instance

docker exec -it php ./artisan key:generate
docker exec -it php ./artisan migrate

If you prefer, you can connect to the container and run Artisan from inside it

docker exec -it php ash
./artisan --help

Queue

Supervisor is used to automatically run Laravel queue workers. You can customize the configuration by modifying php/supervisord.conf file.

TODO

  • Add Nodejs to the stack to compile Laravel assets.

Releases

No releases published

Packages

No packages published