Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local Docker dev environment via Laravel Sail #20

Open
2 of 4 tasks
DerpgonCz opened this issue Aug 9, 2022 · 0 comments
Open
2 of 4 tasks

Local Docker dev environment via Laravel Sail #20

DerpgonCz opened this issue Aug 9, 2022 · 0 comments

Comments

@DerpgonCz
Copy link
Contributor

DerpgonCz commented Aug 9, 2022

Suggestion: Add Docker local dev environment

Why

In order to make project development on local machine faster, more effective, and easier for people who want to run it, as well as existing developers, so nobody has to install all the dependencies on their local machines and bloat the application space.

What

Laravel Sail is a light-weight command-line interface for interacting with Laravel's default Docker development environment. Sail provides a great starting point for building a Laravel application using PHP, MySQL, and Redis without requiring prior Docker experience.

How

The first Sail setup is super easy. I already set it up and tested. So far, all the features I have tested work, but I did not do any deep testing. Part of the bundle is a local Mailhog setup, which works flawlessly and I can register and verify my e-mail.

For running the project, only Docker and Docker Compose will be required.

The rest will require just a few commands:

  1. Copy .env.example to .env
  2. Install composer dependencies (in order to pull the Laravel Sail bash files, needed only once)
    • docker run -it -v "$PWD:/app" composer composer install --ignore-platform-reqs
  3. Run the project
    • ./vendor/bin/sail up -d
  4. Run DB migrations (needed only once or on migration addition)
    • ./vendor/bin/sail artisan migrate
  5. Link storage (needed only once)
    • ./vendor/bin/sail artisan storage:link
  6. Install NPM dependencies (needed only once or on package changes)
    • ./vendor/bin/sail npm install
  7. Run the NPM dev build
    • ./vendor/bin/sail npm run dev

Output for versions

PHP:

PHP 8.1.5 (cli) (built: Apr 21 2022 10:15:06) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies
    with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans

MySQL:

Server version: 8.0.27 MySQL Community Server - GPL

NPM:

8.10.0

TODO:

Known issues

  • When Vite WS losts connection, it tries to ping Vite for availability, and fails, because it calls http://localhost/__vite_ping whereas it should call http://localhost:5173/__vite_ping.

URLs

Reminder

This environment setup is not meant or recommended for production purposes. If it is ever needed to use Docker for production, I recommend creating a separate docker-compose.prod.yml file and deploy the app using that file rather than the default docker-compose.yml. If the app is meant to be deployed to a shared hosting, this setup does not collide with that idea.

@DerpgonCz DerpgonCz changed the title Local Docker dev environment Local Docker dev environment via Laravel Sail Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant