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.
- Click
Use this template
thenCreate a new repository
- Clone your newly created repository
- Copy the env file by running
cp .env.example .env
- Create and run the docker containers by
docker-compose up -d
- Navigate in the created container
docker exec -it php sh
- Run the commands below to start your Laravel application
composer install
php artisan key:generate
php artisan migrate:fresh --seed
- Clone the repository by running
git clone git@github.com:RinMinase/laravel-docker-template.git
- 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
- Copy the env file by running
cp .env.example .env
- Create and run the docker containers by
docker-compose up -d
- Navigate in the created container
docker exec -it php sh
- Run the commands below to start your Laravel application
composer install
php artisan key:generate
php artisan migrate:fresh --seed
- Download the repository as a zip file
- Copy the env file by running
cp .env.example .env
- Create and run the docker containers by
docker-compose up -d
- Navigate in the created container
docker exec -it php sh
- Run the commands below to start your Laravel application
composer install
php artisan key:generate
php artisan migrate:fresh --seed
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
- container name:
nginx
(which houses the webserver that runs your code in a browser)- container name:
webserver
- container name:
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
- container name:
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
- Updating
PHP
- Modify the version text under
docker-compose.yml
underservices : php : build : args
,PHP_VERSION
- Example here:
- You can find the php versions possible here
- Modify the version text under
- Updating
nginx
- Modify the version text under
docker-compose.yml
underservices : nginx : build : args
,NGINX_VERSION
- Example here:
- You can find the nginx versions possible here
- Modify the version text under
- Updating
db
- Modify the version text under
docker-compose.yml
underservices : db : image
, and change the version of the image name - Example here:
- You can find the postgres versions possible here
- Modify the version text under
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.
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 usesmusl-libc
and requires a sad and annoying workaround for it to work
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).