DEV Community

Cover image for Create your first Laravel Project on Docker using Laravel Sail
Chandresh Singh
Chandresh Singh

Posted on

Create your first Laravel Project on Docker using Laravel Sail

There are multiple ways to develop and run Laravel project on your system but here is the easiest way to create your Laravel project on docker using Laravel Sail which is a light weight command line interface for interacting with Laravel's docker configuration.

All you need to do is install docker on your system, you can use either Docker cli or Docker Desktop and rest of the thing are all taken care by Laravel Sail.

Before we start, if you want then you can also watch this tutorial.

Let's Start!

To install Docker Desktop, Click here.

After Docker is installed and running, run the following command to create a new Laravel Project.

curl -s https://laravel.build/example-app | bash
Enter fullscreen mode Exit fullscreen mode

After your project is created, go inside your application directory and start Laravel Sail.

cd example-app

./vendor/bin/sail up
Enter fullscreen mode Exit fullscreen mode

Once done, You can access your application at http://localhost.

You can execute all your commands like this:

./vendor/bin/sail php --version

./vendor/bin/sail node --version

./vendor/bin/sail php artisan list
Enter fullscreen mode Exit fullscreen mode

You can also create an alias for sail if you don't want to type vendor/bin/sail repeatedly.

alias sail='bash vendor/bin/sail'

Enter fullscreen mode Exit fullscreen mode

Then you can execute your commands like this:

sail php --version

sail node --version

sail php artisan list
Enter fullscreen mode Exit fullscreen mode

To stop all your containers, you can type Ctrl+C or you can also use sail down command.

Hope you find this useful.

Top comments (4)

Collapse
 
amineheroual profile image
Am1n3 H3r0

this command curl -s https://laravel.build/example-app | bash start a new laravel project right but with the latest version in laravel
so if i want to start a project but with version 8.x or 7.x how i do ?
thanks @Chandresh Singh for this post is very helpful

Collapse
 
afzal_haq profile image
Afzal98-png

docker: Error response from daemon: the working directory 'C:/Program Files/Git/opt' is invalid, it needs to be an absolute path.

What should i do

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
tuanbtre profile image
tuanbtre

open file docker-compose.yml. find ports: - '${APP_PORT:-80}:80' . change to what you want.