• Stars
    star
    2,305
  • Rank 19,976 (Top 0.4 %)
  • Language
    Dockerfile
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A docker-compose workflow for local Laravel development

docker-compose-laravel

A pretty simplified Docker Compose workflow that sets up a LEMP network of containers for local Laravel development. You can view the full article that inspired this repo here.

Usage

To get started, make sure you have Docker installed on your system, and then clone this repository.

Next, navigate in your terminal to the directory you cloned this, and spin up the containers for the web server by running docker-compose up -d --build app.

After that completes, follow the steps from the src/README.md file to get your Laravel project added in (or create a new blank one).

Note: Your MySQL database host name should be mysql, not localhost. The username and database should both be homestead with a password of secret.

Bringing up the Docker Compose network with app instead of just using up, ensures that only our site's containers are brought up at the start, instead of all of the command containers as well. The following are built for our web server, with their exposed ports detailed:

  • nginx - :80
  • mysql - :3306
  • php - :9000
  • redis - :6379
  • mailhog - :8025

Three additional containers are included that handle Composer, NPM, and Artisan commands without having to have these platforms installed on your local computer. Use the following command examples from your project root, modifying them to fit your particular use case.

  • docker-compose run --rm composer update
  • docker-compose run --rm npm run dev
  • docker-compose run --rm artisan migrate

Permissions Issues

If you encounter any issues with filesystem permissions while visiting your application or running a container command, try completing one of the sets of steps below.

If you are using your server or local environment as the root user:

  • Bring any container(s) down with docker-compose down
  • Replace any instance of php.dockerfile in the docker-compose.yml file with php.root.dockerfile
  • Re-build the containers by running docker-compose build --no-cache

If you are using your server or local environment as a user that is not root:

  • Bring any container(s) down with docker-compose down
  • In your terminal, run export UID=$(id -u) and then export GID=$(id -g)
  • If you see any errors about readonly variables from the above step, you can ignore them and continue
  • Re-build the containers by running docker-compose build --no-cache

Then, either bring back up your container network or re-run the command you were trying before, and see if that fixes it.

Persistent MySQL Storage

By default, whenever you bring down the Docker network, your MySQL data will be removed after the containers are destroyed. If you would like to have persistent data that remains after bringing containers down and back up, do the following:

  1. Create a mysql folder in the project root, alongside the nginx and src folders.
  2. Under the mysql service in your docker-compose.yml file, add the following lines:
volumes:
  - ./mysql:/var/lib/mysql

Usage in Production

While I originally created this template for local development, it's robust enough to be used in basic Laravel application deployments. The biggest recommendation would be to ensure that HTTPS is enabled by making additions to the nginx/default.conf file and utilizing something like Let's Encrypt to produce an SSL certificate.

Compiling Assets

This configuration should be able to compile assets with both laravel mix and vite. In order to get started, you first need to add --host 0.0.0.0 after the end of your relevant dev command in package.json. So for example, with a Laravel project using Vite, you should see:

"scripts": {
  "dev": "vite --host 0.0.0.0",
  "build": "vite build"
},

Then, run the following commands to install your dependencies and start the dev server:

  • docker-compose run --rm npm install
  • docker-compose run --rm --service-ports npm run dev

After that, you should be able to use @vite directives to enable hot-module reloading on your local Laravel application.

Want to build for production? Simply run docker-compose run --rm npm run build.

MailHog

The current version of Laravel (9 as of today) uses MailHog as the default application for testing email sending and general SMTP work during local development. Using the provided Docker Hub image, getting an instance set up and ready is simple and straight-forward. The service is included in the docker-compose.yml file, and spins up alongside the webserver and database services.

To see the dashboard and view any emails coming through the system, visit localhost:8025 after running docker-compose up -d site.

More Repositories

1

larametrics

A self-hosted metrics and notifications platform for Laravel apps
CSS
618
star
2

subvert

Generate subtitles, summaries, and chapters from videos in seconds
PHP
550
star
3

cleaver

🔥🔪 A blazing-fast static site generator using Laravel's Blade templating engine
PHP
264
star
4

fleet

Run multiple Laravel Sail websites locally with custom domain names and https
PHP
234
star
5

docker-compose-wordpress

A docker-compose workflow for local WordPress development
Dockerfile
203
star
6

github-receipts

Source code that powers my GitHub issues receipt printer
PHP
182
star
7

use-the-keyboard

A collection of keyboard shortcuts for Mac apps, Windows programs, and websites.
Blade
154
star
8

laravel-job-board

A modest job board platform built with Laravel. Follow along with the videos below to get an in-depth look at its development.
PHP
122
star
9

laravel-vue-stripe-cashier

A very basic ecommerce app built with Laravel, Vue, and Cashier (Stripe)
PHP
55
star
10

simple-toggle-sites

A very basic Chrome extension to quickly block or unblock a list of websites
SCSS
53
star
11

size

Simple PHP helper to convert bytes to different sizes
PHP
47
star
12

cleaver-directory

🔥📍 A blazing-fast static site generator for local directories built with PHP and Laravel's Blade
Blade
47
star
13

laravel-links

A Linktree clone built with Laravel featuring user accounts and visitor information
PHP
39
star
14

video-laravel-docker-deployment

The source behind the Docker deployment with Laravel video
PHP
36
star
15

listpal

A synchronized to-do app built with Laravel, Vue, and laravel-websockets
PHP
36
star
16

reqon

Effortlessly intercept and inspect http requests
TypeScript
29
star
17

laravel-grafana-dashboard

A simple data dashboard built with Laravel, MySQL, and Grafana, all tied together under a Docker network
PHP
28
star
18

laravel-scheduled-tasks-docker

An example set up for using Laravel's scheduled tasks with Docker
PHP
25
star
19

docker-compose-traefik

A basic example of a reverse proxy with Docker Compose and Traefik
PHP
24
star
20

andrewber

Final source code from the "Build A Ride Share App with Laravel and Vue" tutorial
PHP
23
star
21

geolocation-google-maps-vue

The source code behind the "Adding Geolocation and Google Maps to Vue Applications" video
Vue
21
star
22

video-auth-vue-laravel-sanctum

The source code behind the "Authentication in Vue using Laravel Sanctum" video
PHP
14
star
23

video-populating-google-map-vue-laravel

The source code for the app shown in my Populating a Google Map with Vue and Laravel video
PHP
13
star
24

video-amazon-s3-storage

The source code in the "Getting started with Amazon S3 storage in Laravel" video
PHP
13
star
25

video-auth-laravel-passport

Source code behind the "Getting started with Laravel Passport and OAuth2" video
PHP
12
star
26

laraplace

A basic r/place clone built with Laravel and Vue using websockets for real-time interactivity.
PHP
9
star
27

video-5-laravel-eloquent-tips

The source code for the app shown in my 5 Tips For Supercharged Laravel Eloquent Queries video
PHP
9
star
28

mdsee

Easily view markdown files in the browser and automatically see any changes
JavaScript
9
star
29

lc-the-docker-tutorial

Source code behind the Laracasts series: The Docker Tutorial
Dockerfile
7
star
30

jstophp

A (very) basic list for JavaScript developers interested in learning PHP
EJS
6
star
31

dices-pizza

Example pizza tracking app built with Laravel, React, and Inertia.js
PHP
5
star
32

lc-image-uploading-vue-laravel

Source code behind the Laracasts Series: Image Uploading with Vue and Laravel
PHP
5
star
33

basic-feeds

📜✏️ A simple PHP library to generate RSS and Atom feeds
PHP
4
star
34

site

Source code behind aschmelyun.com, built with Cleaver
PHP
4
star
35

jira-external-links

Chrome extension that opens external Jira links in a new tab
JavaScript
4
star
36

active-links

Update link classes if their href matches the current url
JavaScript
4
star
37

rpi-home

The source for my Raspberry Pi home server powered by Docker + Laravel + Grafana + Vue
PHP
3
star
38

video-vue-converting-composition-api

The source code behind the video "Converting a Vue component to the Composition API"
Vue
3
star
39

dates.wtf

The source behind dates.wtf
JavaScript
3
star
40

cleaver-site

The source behind usecleaver.com
Blade
3
star
41

laravel-auth-videos

The source code behind the series of videos produced on Laravel's authentication options
PHP
3
star
42

quickmetrics-laravel

Making integration with quickmetrics.io easier for Laravel apps
PHP
3
star
43

gpc

General purpose containers - A handy bash file for running common Docker containers
Shell
2
star
44

parody

Create a fully-featured, pre-populated test API with authentication built in
Dockerfile
2
star
45

parody-blog

A blog style API scaffold for Parody
PHP
2
star
46

taro

A blazing-fast static site generator that uses JSON content files and the Laravel blade templating engine
PHP
2
star
47

lc-larabit-favorite-laravel-collections-methods

Source code behind the Laracasts Larabit: My Favorite Laravel Collections Methods
PHP
2
star
48

lc-larabit-mysql-json-columns

Source code behind the Laracasts Larabit: Using MySQL JSON Columns with Laravel
PHP
2
star
49

lc-larabit-first-typescript-component

Source code behind the Laracasts Larabit: Create Your First TypeScript Component
Vue
1
star
50

ffgen

A command-line wrapper for the fontfacegen package
JavaScript
1
star
51

lc-larabit-pinia-overview

Source code behind the Laracasts Larabit: Pinia Overview
Vue
1
star
52

laravel-coreui-starter-kit

A Laravel and CoreUI-powered dashboard starter kit
PHP
1
star
53

lc-larabit-manipulating-photos-intervention-image

Source code behind the Laracasts Larabit: Manipulating Photos in Laravel with Intervention Image
PHP
1
star
54

lc-offline-first-vue

Source code behind the Laracasts Series: Let's Build an Offline-First Vue App
JavaScript
1
star
55

larametrics-docs

The source behind larametrics.com
JavaScript
1
star
56

endive

Simplistic SCSS framework to assist in rapid front-end development
CSS
1
star
57

lc-larabit-whats-new-in-alpinejs

Source code behind the Laracasts Larabit: What's New in Alpine.js (Dec 2021)
CSS
1
star
58

github-actions-docker-phpunit

Example project using phpunit for the GitHub Actions Docker video
PHP
1
star
59

laravel-docker-site

The source behind the laraveldocker.com website
PHP
1
star
60

passhints

A collection of password hints and requirements for websites and mobile apps.
SCSS
1
star
61

parody-todo

A to-do list style API scaffold for Parody
PHP
1
star
62

aschmelyun.com

The source of aschmelyun.com
HTML
1
star
63

lc-larabit-db-query-gotchas

Source code behind the Laracasts Larabit: Common Database Query Gotchas
PHP
1
star
64

calcite

A front-end framework for rapid web development and prototyping
HTML
1
star
65

textrepo

📝 A super light-weight notes app powered by Vue and IndexedDB
CSS
1
star
66

lc-larabit-creating-using-custom-blade-directives

Source code behind the Laracasts Larabit: Creating and Using Custom Blade Directives
PHP
1
star
67

whatsopentc

What's Open Treasure Coast - A local directory showing restaurants that are open during COVID-19
HTML
1
star
68

lc-larabit-laravel-octane-overview

Source code behind the Laracasts Larabit: A High-Level Overview of Laravel Octane
PHP
1
star