Giter Site home page Giter Site logo

alfredosotil / docker-compose-laravel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ajaxray/docker-compose-laravel

0.0 1.0 0.0 67 KB

Ready made development environment for Laravel 6.x using docker-compose

License: GNU General Public License v3.0

Dockerfile 100.00%

docker-compose-laravel's Introduction

docker-compose for Laravel 6.x

Ready made development environment for Laravel 6.x using docker-compose.

Don't spent hours managing dependencies anymore. Just docker-compose and git - your laravel project will be up and running in minutes!

What's Included?

The environment is composed with the following services -

  • PHP 7.2 with fpm
    • All common dependencies for Laravel application
    • Composer
    • nodejs and npm for Vue.js and Laravel-Mix
    • ImageMagick + ghostscript (default) or gd (require uncommenting) for image operations
  • Nginx - Web server
  • MariaDB 10.2 - Database (drop-in replacement for MySQL with performance, stability, and openness)
  • Adminer - Light-weight database management frontend
  • MailHog - Receive emails for dev environment (Web and API based SMTP service)

How to use

I am assuming you have basic idea about how to work with git, docker and composer based PHP projects. Otherwise, following the steps may not be easy for you.

1. Clone this repository

You can clone it anywhere in your local machine or download as zip file.

git clone https://github.com/ajaxray/docker-compose-laravel.git /tmp/docker-compose-laravel  

If you want to try with fresh Laravel project, check "Starting with fresh Laravel" below in Notes section before proceeding to the next step.

2. Copy required files to your project

Now, copy docker-compose.yml file and docker directory to project root of your laravel application.

cp -vr /tmp/docker-compose-laravel/docker* /path/to/my-project/
cd /path/to/my-project/

3. Adjust .env variables

Edit the .env file in project root and set the following values:

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=appuser
DB_PASSWORD=123456

MAIL_HOST=mailhog
MAIL_PORT=1025

Alternatively you may update parameters in docker-compose.yml file and set .env parameters accordingly.

4. Get up and running

Start containers from project root directory

docker-compose up -d
# Check service status
docker-compose ps

If everything went OK, you should see something like this -

docker-compose laravel screenshot

That means your Development environment is ready! But we have one more step before checking the live application.

5. Generic Preparation for Laravel application

These are generic steps to prepare any Laravel application, not specific to this Docker setup. But you need to run them from inside appropriate container.
(You may ignore any of the following commands if not required for your project.)

docker-compose exec app composer install --no-interaction --no-suggest --no-progress --prefer-dist
docker-compose exec app php artisan key:generate
docker-compose exec app php artisan migrate
docker-compose exec app php artisan db:seed

# Required for Vue.js and laravel-mix
docker-compose exec app npm install
docker-compose exec app npm run dev

# Cache configuration. Recommended for production environment
docker-compose exec app php artisan config:cache

๐ŸŽ‰ Good News ๐ŸŽ‰ - Your project is live by now!

Check it here:

The information above can be different if you've modified parameter values in docker-compose.yml.

Important Notes

  • Starting with fresh Laravel

    If you have not started (or cloned) the project yet, you can start a latest Laravel project using ONLY git (no other dependencies):

    git clone https://github.com/laravel/laravel.git my-project
    cd my-project
    cp .env.example .env
  • Updating PHP configuration

    docker/php/local.ini is being loaded with PHP ini of app service. So, if you need to modify/add any ini value, you can use this file.

  • Updating Nginx configuration

    All config files under docker/nginx/conf.d/ will be loaded by Nginx. You can modify/add files here to modify Nginx config.
    The application hosting is defined in app.conf of this directory. Check it to know log file locations and other configurations.

  • Updating Database configuration

    docker/mysql/my.cnf is being loaded with database configuration of db service. So, if you need to modify/add any configuration, use it.

  • Connecting database from other database client

    To avoid conflict with local MySQL (if any), database port mapped to 33061 for localhost. That means, if you want to connect the database inside container from a database client, you have to use 33061 port.

  • Selecting Image library

    ImageMagick and ghostscript is enabled by default. If you prefer GD instead, comment out ImageMagick section and uncomment GD section in docker/php/Dockerfile

  • Add/Remove/Modify services of docker-compose

    If you need to add/remove/modify any service anytime later (after docker-compose up), feel free to do. Just remember to run the following commands from project directory to apply your changes -

    docker-compose down
    docker-compose up --force-recreate --build -d
    docker image prune -f

docker-compose-laravel's People

Contributors

ajaxray avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.