Getting Started using Laravel Sail for Docker on WSL 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi i'm adam kolp and you're at beachcast in this video we're going to talk about using laravel sale for docker on wsl2 so stick around and we'll get right on that [Music] welcome back as i said in this video we're going to be talking about laravel sale now i've done videos in the past about you setting up laravel on a docker environment and i've also set up laravel on a wsl environment but in this video it was a little bit different one of my past viewers requested that i do a video on setting up laravel on docker now i think that person probably didn't realize that i had already done that a few years ago but since it was a few years ago i decided to try out something new and show the docker setup again but this time with a new wrinkle using laravel sale in my previous video when i set it up there were some things that you had to take care of because of the caching directory permissions and also the config and a lot of other places where certain permissions were needed in order to run a local development environment and doing it in docker was not without its limited issues so that being said laravel sale kind of takes care of that so let's go ahead and dig right in to get started i'm first going to start off in the laravel sale documentation now in the documentation in the introduction it tells you a little bit more about what it is laravel sale is a lightweight command line interface for interfacing with laravel's default docker development environment it also provides a great starting point to build level applications using php mysql and reddit without prior docker experience one of the things i did note however as i was preparing for this video is it does state that laravel sale is automatically installed on all new laravel applications unfortunately that's not always the case in my previous video which i'll link to up above i installed laravel using composer and just did composer create project and by doing that in bringing laravel laravel it didn't bring in sale by default so what the documentation is referencing is installing laravel the example application now sale is in the example application it is not there if you make the command composer create project so if you used a composer create project you would have to follow the command that is here which is composer require larval sale and then hyphen hyphen dev you would need to do that if you were not using the laravel example application let me show you a little bit more of what i mean all right so to get started i'm going to go ahead and launch my installation of ubuntu 2004 now i do have a wsl2 environment set up and ready and it is running ubuntu 2004 and that is the command line that i just brought up the terminal that i just brought up so if i if i look at my present working directory i am in slash home slash atom call now this is on windows and but yet i'm at an abu to command line because that is the environment that i'm running in wsl too at the moment if i look in that directory i have some various other subdirectories projects is the one that i'm going to be working with right now so let me go ahead and change into the projects directory and if i list what's there we can see that i have an example application and i also have sample site now the example hyphen app it was installed using the laravel installation of the example app the sample site was one that i installed using composer to create a new project if i if i go into sample site and we look at the files there we can see that it's just a standard uh level application install by using composer and installing laravel laravel if i if i do a list then of the vendor directory vendor and go into bin and we see what's there we see i don't have sale here that being said i'm not able to issue laravel sale commands now so i would need to install laravel sale in this project and to do that i would issue the command composer require laravel slash sale and then hyphen hyphen dev however if i go to the other project go to the example app and i bring up all the files there and for instance if i if i list the contents of vendor bin we see that i do have sale there so it is ready to be run from the the vendor bin folder because it was installed along with the example application so in this case i don't really i don't have to do anything else to use laravel sale let me clear and get back if it now from here if i wanted to run laravel sale i can do that by uh just typing dot slash vendor bin sale and issue the command up now when you do that it basically does a docker compose up and runs laravel on a docker in a darker environment from this local local directory so we'll wait for that to finish up okay so that is up and running right now uh and because of the fact that i ran uh the laravel sale up uh we can we can go over and look inside docker and in docker we can see that i have an example app running and i've got multiple other things running within this application as well there's selenium there's mailhog mysql millisearch there's also a redis here and then the laravel app all of those are running within that example app in that stack and also if i look in the images there's now a full list of images that were pulled down and used to create those containers and the container is up and working right now because i ran it the way that i did using sail up my terminal now acts as a it's feeding back all of the traffic and everything that's going on so if i and you can see that occasionally it's it's cycling through if i go to localhost and bring that up uh in just a second it'll bring it up and we'll see that the level application is running and we're getting it served up in in the in the page here now there's a better more convenient way to run this so let's go ahead and do that for the moment i'm going to hit ctrl c to exit out of the application and now that is going to stop the environment and uh and shut it all down and right now if we look in docker we can see that things are still running and they're in the process of shutting down and so that way they're not actively running when when you exit out it's going to shut down the containers okay so now it is exited so now some of the changes that i want to make is i want to make this a little bit easier to use one of the easiest ways of course since i'm doing it inside the terminal is to instead of always having to type dot slash vendor slash bin slash sale it would be nice if that were aliased and so i'm gonna go ahead and alias that in my uh my terminal so by putting in this command let me go ahead and clear and start back at the beginning here i'm gonna put in that command so i'm aliasing sale and i'm telling it what to do in the bash script and how it's supposed to use the vendor bin sale location so hit enter on that so now that should alias the sale command so if instead of using the vendor bin sale now i should be able to do something like sale up and it's basically issuing the same command it's going to restart up the containers and now i'm still going to be dropped at the terminal and it's still going to give me any log output but it's a lot easier to remember to get it up and running you don't have to worry about the vendor bin sale so let me go ahead and hit ctrl c again to exit out of it so let it stop running now another thing that i want to do though is instead of always having to keep my terminal open once i have that environment up and working it'd be a lot nicer to run it in detached mode so that's what i'm going to do so now that this now that it's stopped i'm going to clear clear and go back to the the fir the beginning prompt uh instead i'm going to type or put in the command sail up and i'm going to put hyphen d to put it in detached mode now once i do that it's going to go through the same steps of kicking everything off but then it drops me back to a command line where i'm able to function however if i go over to the containers we see that they are in fact still running so they're still running and but i'm in detached mode so i'm not occupying my terminal and i still have my terminal available for other things now alternatively if i want to shut this down then instead of hitting ctrl c as i was doing before i'm in detached mode so i would have to issue the command sail stop and that would stop the containers okay now that everything has stopped i'm going to once again start it back up again still in detached mode and let it bring everything back up because there's some other commands that i want to show you sale has some other handy commands that come along with the command line utility such as if i were to type sale php hyphen hyphen version then it will give me back the version of php that i'm using inside the container you can see here inside the container i'm running php 8 8.0.12. now in ubuntu i don't have that if i were to do php hyphen v in php you can see that inside the wsl2 environment i'm running php 7.4.3 so we can see that sale is giving me back the php information from within the containers created by sale i could run pretty much any php command i wanted using sale and and it would pass the command through to php it would also make it easier for me to run composers so if i wanted to do something like sale composer and for instance i could do list and to give me a list of the composer commands or run any other composer command it's all right here composer is available and sale is passing that through to me so it does make it very convenient to be able to access php or composer to do other things from within the sale environment alternatively i could use sale for other things as well so for instance if i wanted to find out the version of node that i had installed node.js i could do sale node and do version of node and it would give me back the version of node.js that i'm currently running inside that environment as well which is 16.13.0 and i could issue other node commands or even npm commands if i wanted to do node package manager and install some different packages i could do that just the same if we wanted to run tests we could do a sale test and let it run our test for us and we can see here the results of the tests where the tests are two different tests and they both passed now keep in mind it does take a little bit longer to run commands because we are running them in docker and the the local files are all in the host system so it does take a little bit of time but it's not too terrible and it's pretty usable in most situations you may need to adjust the way that you're doing things depending on your environment and how your application is set up you know and what speed that you really need you know in a development environment but for most practical use cases this is going to be sufficient something else to note is we also have the availability of the shell from within the containers if i issue the command let me clear my screen if you issue the command sail shell it will bring up the shell terminal inside the container so then any commands that i'm issuing are inside the container and i'm able to function that way if i exit out brings me back to my command prompt inside the wsl environment and but i could have run any commands i wanted to inside inside the shell of the container it also gives availability of tinker so if i wanted to use tinker i could issue the command sail tinker and any other sub command of tinker so this was just a real quick video to get you up and working and hopefully experimenting with laravel sale a little bit the folks who requested me to do another docker tutorial hopefully this was helpful hopefully all of you found this helpful it's the easiest way to get a docker application up and working using laravel sale for a laravel application inside a docker container and again it doesn't really require a lot of docker experience or know-how to do it it's very easy to get up and working really quickly i wish you the best of luck let me know how it goes for you leave a comment and let me know if you tried laravel sale and how you found the experience as well i look forward to hearing from all of you uh if you found this video helpful or if you found that it helped push you in the in the direction to give that a try give the video a like so that way others in the community will know about the video and find it in in the search i really appreciate your help and hopefully i'll get to see you again in the next video thank you
Info
Channel: Beachcasts Programming Videos
Views: 7,173
Rating: undefined out of 5
Keywords: using laravel sail for docker on wsl 2, laravel docker, laravel development docker, laravel docker windows, docker laravel tutorial windows, laravel sail, using laravel on docker with sail, laravel with docker, laravel docker windows 10, laravel sail windows 10, laravel 8 docker, beachcasts, adam culp, web development tutorial, php programming videos, adamculp, php tech videos, laravel sail windows, laravel sail tutorial, laravel docker-compose, laravel development environment
Id: Zxi157MpoRE
Channel Id: undefined
Length: 14min 49sec (889 seconds)
Published: Tue Nov 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.