Docker + Laravel + MySql + Nginx + Composer

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome to this video in this video i will show you how easy it is to manage development environment uh using docker and its containers for your next level project i will explain how docker manages your project dependencies using containers and what are the advantages over traditional installation approach so in traditional approach we have to install many things before we again we can actually run the project in the browser for instance we have to install a web server database scripting language composer or npm to manage the project dependencies in many cases if we want to run a project on real-life url then we have to also create virtual host in web server and on top of it we have to run quite a few commands like composer install or php rt sun key generate or php rt sun migrate what is we can automate all of these steps i wouldn't it's a lot of development time if we can set up the whole project on staging or develop a production server with just one command let me show you how so before we get started we have to ensure that we have a few things installed in the system first thing is docker so i'm running on logo version 20.10 next thing is docker compose so i am by the time of this recording i am running on 1.29 and the last thing that is good it is optional but i just want to demonstrate how you can set up the git project using docker so i have installed the git so i am running on bit version 2.25 let me clear this out so i i have set up everything in my system and i will just quickly walk you through with each and every steps just just to save the time so first thing is we have to create the docker dash compose dot yml file i have already created that and you can see uh some of the code is written here and i will explain each and every steps so first thing is version i have set the version as 3.8 second thing is networks and i have uh set up one network that is laravel and provided a driver as a bridge and i have provided subnets uh like uh internal ips between 0 to 24 range second thing is services and in that services i have defined all the services that are essential for me to run the laravel project starting from nginx as a web server mysql as a database admin as a database gui tool or like debugging tool or just to run queries php as a scripting language composer to maintain or manage dependencies in many cases you also require npm but i have not taken as an example of it but if you need you can just define that next service just below the composer to install that okay now let's start with the nginx so for nginx i am using image ngmax as a weak stable alpine tag and how you can get that and just go to nginx official docker page and in tags you will get all the available tags from this you can take or you just replace and if you want to for example if you want to use stable perl image tag then you can just replace the whole thing with this one i am speaking with stable alpine tag then the container name you can define any container name you want so i am just taking with the nginx second thing is ports so nginx usually run on 80 but you can map the port with a container port with the local port so in my local for instance i have something running on port number 80 so i have provided a default port is 8081 so whenever the nginx starts it will map containers 80 port with my local systems 8 1 port and it will start the nginx service then the volume so this is very tricky part but it is also very essential so i am mapping the volume so whenever the nginx container install it will map this directory where www.html of nginx container with my local directory src so as of now you can see this src folder next volume is default.com i have overwritten that a configuration to run my project on lara on a virtual host like dave.laravel.losing so if you are standing here i have defined the root as var www.html then code and public because my index.php resides in public but uh the one note to highlight is rather than providing the absolute part of the project i have replaced the path src with www.html uh remember that is essential because we have mapped the project path with src through vrw html and we are running this project in container not in local system a rest of the code is boilerplate and i have just copied that from nginx configuration file next is mysql so just like nginx i have copied the mysql tag is as 5.6 as i want to run the mysql version as a 5.6 but if you want to run that or upgrade the version you can just go on official mysql docker page and then you can just google through the tags so you can use tags as latest 8.2.26 or 8.0 as as per your project needs i'm just speaking with 5.6 uh there are few of the settings which are not covered in nginx service that is command so as of now in mysql we are instructing the mysql container to use a default authentication plugin sorry as a mysql native password we are mapping the ports from 3306 sorry uh 3306 with 3307 in my local system and also the volume so whatever resides in var leave my sequel that has to be mapped with mysql folder so it covers everything like the database that we are going to create that is uh that will be covered in my sql folder and uh other project other mysql dependencies or files that you want to overwrite you can just map that or you can just override that within this folder also in the environment i am defining my user as a root sorry i root password as one two three four and i am defining a new user as a mysql with same password and my database name would be database all these settings are customs and you can change it as you want also i am instructing this container or service to stay within the network level uh with mysql i also want to cover the admin so edmunder is straightforward uh it be a default run on 8080 but i am running that on 8082 and also instructing that into running into the same uh network so that all the containers can communicate with each other uh the next service is php so php is a bit different than other services in other services we were defining the image like which image we want to use and what version of the image that we want to use by defining the tag besides the image if we don't define the tag then it takes the latest as a default but php is different and how it so uh let me show you so first we have instructed it to build the context from docker file docker file so i have created this docker file and in that i am defining from php 7.4 fpm so this is a new but it is quite the same so uh what we are doing is uh here we are instructing the docker compose to build my php from php 7.4 fpm as a base image and i want to perform quite a few things before we go further so whenever we run docker compose up command it will come to php and then it it understands that rather than the direct image we want to do some operations uh on the image so we have used the build and we have defined the docker file where we have defined all the operations so first thing that we have defined is the base image that we want to use it is the same just like any other container we have defined php with the tag 7.4 and we want to copy the latest composer so this is also another image this is the image name and this is the tag name and so we are instructing the uh docker to install composer and um map that in user being composer of php with user local bin composer of the composer so uh with this line of code uh what we have done is like in php container we have installed composer container so later on uh in the project when we run to you then we want to run a composer install or when we want to install a new dependencies uh in the composer.json file then this will be helpful and then we are instructing a docker to install pdo and pdo mysql extensions in php 7.4 to communicate within mysql moving forward we have installed docker as a sorry composer as a separate uh service too and here we have defined the command so it is kind of same container name uh composer image we are using composer latest and we are defining the command composer installed also depends on php so first it will uh install the php and then it will install the composer the last option is restart always so i'm instructing the composer to restart this container or any container with this option i think i have defined this option in almost all the containers so it will restart the containers as in when i run the command docker compose of hyphen d now let me go to the terminal and one command so i am running this command as a super user locker compose build sorry build [Music] this will build the containers and run the containers in detach mode wow okay so at this point i have uh created all the containers and i have up the containers but there are few things remaining before we can actually see the project running in the browser first thing is we have to download the project using git and then second thing is we have to run a series of commands like composer install composer uh not composer but php uh artisan migrate or keygen grid uh actually uh to run all this uh before we can run the project on the browser so uh for that i have created one install file so this is the best file i'm using to automate the project installation process so as a very first step i'm removing the src folder so is mysql and then creating the src folder again and then taking the git url as an input and cloning the project in src folder and then after uh changing the ownership with my root user and then changing the permission to 777 for storage folder copy env file into the project directory so i have the env file in conf that is outside the project and that is something it is a standard env file but i have only modified the database connection and the app url so that i am copying the then i am bringing down all the containers if they are running building the containers again and running the container in detach mode this tab i don't think it is required for most of you to write in a loop you just need to write this statement but since i'm running in low configuration in my system i'm running this in a loop and i guess in third or fourth attempt it is completing the configuration for darko and downloading the geek and then it runs the key generation so in third or fourth attempt it is like performing this uh operation properly then it clears the config clears the cache again many time i face that my mysql container is not ready before i run this command so i am running that in loop and i guess in third or fourth attempt it is generating a migrations or running the migrations in database for most of you it is not required to run in loop but if you are facing the same problem like me then you can run that in loop or you can increase the loop from 10 to 20 or 30 depending on your configuration so after running the migrations i have two ceilings that i need to run so i'm running those seeders too and that sums up my uh project installation if you have any other uh if you have any other steps that you need for your specific project then you can write that down so if i need to explain this so what we have done is with this command for those who are not like uh familiar with blocker compose so i'm running the docker compose exact php so this php relates to the php here and uh we want to run this command in our php container and the actual command starts from here like php then the whole project artisan path dbc and the class name as a user side so for instance i am running this on php if you want to run any specific command for example on mysql then your command should be docker compose exact and nice equal sorry my sequel and then the actual mysql command that you want to uh run on the uh messier container okay i think we have uh covered everything up and now it is time to run the install file and see how it goes so let me run this file and hit enter it is asking me for the password for the bit url let me provide the bit url and start the installation so i have provided the git url that has created the src folder and within that the code and documents and in that i have my project on laravel setup then it has started the contact stop the container remove the container and then again install the continue then it had failed quite a few times running it for the sixth time in this example my applications are keysight successfully migrations are running and at the last tab it has seeded the database in default.com we have defined the server name so let me just copy that we are running on 8081 and we have been redirected to login page as you can see the project is running also let's check the add menu so admin is running on eight zero eight one i guess not eight zero eight one uh adminer is running on pixel [Music] so as a server we have to provide db because uh container uh sorry docker is using internal ip mapping so we just need to define the sorry not the db we have to define the name that we have used and we have used a mysql name as mysql and our adminer is running here so everything is now set up uh without installing anything uh in the local system and continue containerizing uh our application using darko so next time whenever you are installing the project you just need to run install file and it will do everything for you that will save a lot of time especially when you are setting up a project on a new server or your peer developer is setting up a project for the first time in his system that will be very helpful for them too thanks thanks for watching this video if you have any suggestions please provide me in the comment section you
Info
Channel: Rukmi Patel
Views: 1,010
Rating: undefined out of 5
Keywords: docker, php, mysql, adminer, laravel, laravel7, run-laravel-project-using-docker, project-automation, web-server, database
Id: IvDya1PibV4
Channel Id: undefined
Length: 24min 22sec (1462 seconds)
Published: Sun Sep 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.