Git Product home page Git Product logo

laravel-docker's Introduction

docker-compose-laravel-app

A simplified Docker Compose workflow that sets up a Laravel network of containers for local Laravel development with Phpmyadmin.

Usage

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

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 Laravel app).

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

The following are built for our web server, with their exposed ports detailed:

  • nginx - :80
  • mysql - :3306
  • php - :9000
  • redis - :6379
  • phpmyadmin - :8081

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

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
  1. If you want to initialize database data with a sql file you should create a docker-entrypoint-initdb.d folder inside ./mysql and put your db.sql file into it.

  2. Samething abour redis container so you should decide about redis persistent data:(optional)

another way of doing the 2,3:

volumes:
  mysql:
    driver: local
  redis:
    driver: local

docker exec container

Access container as interactive shell and see output:

docker exec -it <container id> sh

Tip: You may use /bin/bash or just bash so after installing bash, you should inspect your image to understand CMD part and change current option to whatever you want. For this purpose run:

docker inspect [imageID]

Usage in Production

Tip: Don't forget to install and configure opcache

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.

laravel-docker's People

Contributors

masoudfesahat avatar rezakhademix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-docker's Issues

Dependencies broken

Some dependencies are broken when following the readme installation instructions, first of all i'm getting Package 'oniguruma', required by 'virtual:world', not found, fixing it by removing the mbstring dependency i'm getting another new error Package 'libcurl', required by 'virtual:world', not found

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.