DEV Community

StuartCreed
StuartCreed

Posted on • Edited on

Using Laravel Sail (docker composer for Laravel) on a existing application

sources: https://laravel.com/docs/8.x/sail#installation and https://laracasts.com/series/whats-new-in-laravel-8/episodes/12
requirements: Your project must be using Laravel 8

Install docker: https://docs.docker.com/get-docker/
run: composer require laravel/sail --dev
run: php artisan sail:install
run: ./vendor/bin/sail up

That's it! Gets rid of the errors that occur with homebrew and valet sometimes and isolates your app from your local machine. It is a docker compose set up basically, so you can cd into your proj folder and run docker compose up and this will do the same as ./vendor/bin/sail up - or you can use your docker GUI to stop and start sail.

Other useful link: https://mattstauffer.com/blog/how-to-use-takeout-to-add-new-services-to-laravel-sail-and-save-ram/

If a port is already taken (which is an error that may occur when you run ./vendor/bin/sail up) you can specify a different port to use. e.g. if you are using port 3306 for mariadb on your mac then you can use 3307 for mariadb with your container instead by editing your docker-compose.yml file: Alt Text

If the APP Port is in use and you cannot stop it you can run it on a different port instead:

APP_PORT=89 sail up

for example to change it from port 80 to 89 OR do the following in the docker-compose.yml file to avoid typing the app port every time:

# - '${APP_PORT:-80}:80' # WHAT IS WAS BEFORE
  - "8084:80"
Enter fullscreen mode Exit fullscreen mode

Though bear in mind that you will have to view the port using the new port number: i.e. http://localhost:8084/ instead of the default http://localhost:8080/

Top comments (2)

Collapse
 
rf14 profile image
Arif Zuhairi

i have been looking for this

Collapse
 
pudgeline profile image
Abolhasan Momeni

should I build image after develop app ?