Skip to content

codeliter/docker-compose-caddy-laravel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-compose-laravel-caddy

A simplified Docker Compose workflow that sets up a Linux (Alpine Linux), Caddy, Redis, and MariaDB network of containers for local Laravel development.

Requirements

Usage

  • Make sure you have docker and docker-compose installed.

  • Clone your code into the src directory.

  • Create a .env in this directory.

    • PHPGROUP: This can be the username/group of the current user on the host machine.
    • PHPUSER: This can be the username of the current user on the host machine.
    • DB_DATABASE: This is the database your application wants to use.
    • DB_USERNAME: This is the username the application connects to.
    • DB_PASSWORD: This is the password of the database the application connects to.
  • Navigate to this directory in your terminal, Run:

    docker-compose up -d --build caddy
  • Bringing up the services exposes the following services on your machine:

    • caddy - :8200
    • mysql - :3306
    • redis - :6379
    • app - :9001
    • mailhog - :8025

Available Commands

  • Composer

    docker-compose run --rm composer update
  • Artisan

    docker-compose run --rm  app php artisan migrate
  • Php

    docker-compose run --rm  app php

Persisting MySQL

Persisting mysql to the host machine disk is pretty easy.

  • Create a directory on your machine. Example create a directory in the path: /data/mysql
  • Modify the mysql under the services in the docker-compose.yml
  • Change the volume mapping to the path on your local machine
        volumes:
        - '/data/mysql:/var/lib/mysql'
    
    The /data/mysql must be a directory that exists on your local machine.
  • Kill the container using docker-compose down, then restart.

Persisting Redis

Persisting redis to the host machine disk is pretty easy.

  • Create a directory on your machine. Example create a directory in the path: /data/redis
  • Modify the redis under the services in the docker-compose.yml
  • Change the volume mapping to the path on your local machine
        volumes:
        - '/data/redis:/bitnami/redis/datum'
    
    The /data/redis must be a directory that exists on your local machine.
  • Kill the container using docker-compose down, then restart.

MailHog

The current version of Laravel (8 as of today) uses MailHog as the default application for testing email sending and general SMTP work during local development. The mailhog service is included in the docker-compose.yml file, and spins up alongside the laravel application, redis and mysql services.

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

Using BrowserSync with Laravel Mix

If you want to enable the hot-reloading that comes with Laravel Mix's BrowserSync option, add the following to the end of your Laravel project's webpack.mix.js file:

.browserSync({
    proxy: 'nginx',
    open: false,
    port: 4000,
});

From your terminal window at the project root, run the following command to start watching for changes with the npm container and its mapped ports:

docker-compose run --rm --service-ports npm run watch

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published