How to setup Docker for production Laravel

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone I hope to find you well so let's get let's get one more episode started [Music] hope you're all doing well I can already hear the output of the music so hopefully again able to control it even so it's my first time doing it so please let me know if is it too loud or not say hi in the shed feel free to ask questions [Music] I'll be happy to help and yeah that's it going to start and share my screen okay let's do that [Music] let's go here we go [Music] so if you haven't been following along is this new to you but of course this episode should be self-explanatory by itself but you should follow the content in the channel so you can start from a start from scratch even you can start from start from zero Docker wise all the concepts if you are ready to put this to production to learn how to do this how to do the next steps Jump On In so and until today in the last uh episode we deployed a application with traffic with SSL um for port 8080 and 6 000 no no I mean before we were serving in this part and then after we set traffic all the traffic was to was set to 443 with auto SSL and until then we add a container that's inside the main process because each container is one process and this one process was supervisor and with supervisor does is that under the hood it will start other applications and as much as this might be just enough for the simple use case maybe there are other ones other cases that we want to separate responsibilities per container so this is the setup we are looking for today and what we will do is to convert the last scene scheme into this one so [Music] if this is the VPS with this uh all outer square is the DPS then [Music] this a lot of application will will be done by 3 or even more containers so there will be one container for fpm at green one container for nginx they will speak with each other through TCP traffic [Music] and there will also be one or more workers each worker has its container and also there is cron running and these will be the PHP running containers right after that we will not touch it for today because they are finished it will also have red is running and sakatti for the websockets and my sequel is already running in our setup is not in a different server as it should be to separate persistence from the application I think it's logical to do that well but today we'll focus exactly on the other level application that I'll show you again it stops being just one container with a multitude of services and with it will now be a multitude of containers one per service yeah that's it so that's what we're going to do let's jump in so [Music] I will bring back um our project I don't remember if it's running or not still in the cloud let's see what happens let me check let me check oh and yes it's still running I've forgot to put it up or to delete or maybe I'm not even deleting until the end of the season so going to check because I don't remember the domain I think likely going to remind but as of now I am still not finding so [Music] bring back the previous episodes we have done this episode so multiple applications with auto SSL certificates and traffic this is done but this is laravel application has been done with the more naive or I mean very simple approach which is supervisor so right now so that we'll deploy before this step we are going to Docker production with one copper service well they can scale right but we are top using supervisor yeah that's it okay so enough sale let's go and check the repo Okay so not the repo I meant up into them server [Music] going in so if you remember we have the forge user inside we have apps folder which has the Inspire which is the project we are running and DC whenever whenever I write DC if it's still here it's an alias for Docker compose okay so if I'm gonna say dockerps or DCPS oh right so I need to run I need to provide what compose file to run as you remember the default file naming would be Docker compose Dot whoop sorry sorry I was thinking it was another so dockercompose dot yaml so if there would be a Docker compose dot yaml file Docker would use that and also the docker compost dot override since we don't have that we have to specify which one we want from last episode we have used dockercompose.demo we can check that by checking our history and well this is right now it is running prod because I've already tried it I've already done some stuff to it before this demo so I could start stuff earlier but we've done that with a demo let me check yeah so if we go into our container [Music] or this it's the Inspire service like right so Docker compose config I mean not even needed I'll go into the Container Fe 1 so that's Docker exec minus interactive TTY and let's run in the container fed1 the command bash and we are in right now inside the container which is running the service and I'm gonna do yes minus aux and we can be now sure we are running supervisor so we are running the demo by all we are running on the demo configuration file the one on the left in the scheme and we'll stop doing that right now so cool I've changed this since then [Music] I did so let me check demo file did I put well not this oh let me check let me check what's going on here yes is that let me also check what I changed so this Docker compose I'm gonna say yeah it's the [Music] okay so this Docker compose is where I've made the changes because it's get ignored and we're we're going to start right now okay cool foreign [Music] this thing to be clear with before so this Docker compose dot demo should Point into well it's not exactly a demo but with um it's a basic basic configuration and you can use just that for sure if it's just a small thing so let's rename it to basic let's keep it basic naming in the project and that's it so I shall rename this Docker compose into basic and let's use the basic folder right so let's change it also here to basic and yeah that's it so I've been ahead of time and made few changes and we are going through them right now so what is study production is the it's the preparation I've done for today hey evil glad you joined just now I've seen so yeah one minute ago thank you evil so if you're saying hey good stuff to watch I hope everyone thinks the same we'll be watching you on the second screen as I'm cutting some stuff as well well happy coding evil I hope you enjoy so out of curiosity what is the Inspire service for so evil the Inspire service is a laravel application which is already running in production um I think you've seen running it inside this container and if I if my memory if my memory doesn't fail there was someone saying a name in the last live just a random name so I could generate a certificate SSL with that domain so let's check what that name is so I'm gonna run Docker compose config and yeah Docker compose with the demo yaml file right I'm gonna run config Ure compose minus Dash f with this configuration let's run config so let's check what's the domain is running at the service inspire what is that where is that domain delighting the server because yes maybe sorry evil I'll let me check something if traffic is running and now it is yes it is running so Inspire should have hmm me check I will check on the nameship account I think it was something Viva someone gave a name from the audience for the sub domain one-time password [Music] okay in a second so yeah I used one of my many domains that I have stopped yeah yeah so it's go Viva under a domain name rachel.cc that I just thought before knowing it was a brand already well just one one more domain to the collection and I've set up um goviva dot paige.cc to run this application I will show you right now go viva.pleasure.cc and it's running already so you can find it running already this was the application that I've done when I was giving a talk in PHP Lisbon these Meetup exactly this Edition and what did I do I repair the quiz with the favorite beer for the audience to vote because in the telegram group there was some discussion about beers and I need to just do a project about something so I prepared this laravel application View I thought yeah it's an inertia application and it has web sockets provided by suketti so let's vote for Brahma and if all goes well yeah if you will notice right now Abram is at this level and if I were to vote again if there's three seconds I have to wait yeah it just automatically uh updated right there's a lot going on you can check in the previous episode it's a very naive implementation it's slow one it's not an optimistic one it's a conservative so yeah this is the application that we are running and maybe you did join from the beginning I'll just oh you also like inertia cool so what happened um this application is running inside one container which has supervisor as the main process and then several sub processes right under supervisor and this is good for a basic low traffic just for many many projects right this is plenty this is enough um and it's all already done and in the GitHub repo but today we are going to separate it um so that each service will have its own container even and multiple workers will be multiple containers and also Crown so this is the setup we will finish today oh you also love inertia so no I didn't configure SSR SSR but yeah it's a pretty straightforward right now so yeah that's something we can do also okay so it's it's very easy to do that you know soccer I mean with the pipeline we can just add a line and get it working Okay so also Richard is joining hello Richard I hope you enjoy your stay [Music] okay cool cool yeah also love inertia view in general um okay so let's go okay so our Docker folder as the basic files to do and I've been preparing before [Music] I think I should delete this rod because well this yeah let's delete this let's pretend it's not here can check before going through so yeah this is essentially the same just without the labels right [Music] oh no it's the plot from the last episode right yeah we added inspired traffic host so that's where the [Music] environment variable should leave [Music] yeah dashboard yeah Inspire traffic host go Viva the society is running under WS goviva dashboard is running on this room I hope we'll find the latest episode if you want to see what went around here all this setup today we'll just we will we will dive in into separating [Music] into dedicated containers cool so we'll convert these last production let's see what's going on live right now in this moment from last episode [Music] um we are building an image from the production folder Docker file so it's the same like here and basically it's uh running and pretty standard lightable application just with supervisor and also a crunch should be installed where is that oh yeah so it's running Quran and nginx and their supervisor right and it's serving both static assets and also can run Chrome can run workers and that's it so Evo is commenting something interesting usage of traffic I have only been using it for self-host of projects in a small local VM I have but it is a really nice nice piece of software yeah and I would agree totally I think I will dedicate an episode just for the different configuration because I think the docker provider configuration where we just add labels to containers and it configures just with that right can be a little bit overwhelming or just opaque to some people so I think I will also make one configuration not using labels just files so any reason for not using Alpine another comment as it should produce a smaller image size well um yeah there is a reason I am familiar with Ubuntu workflow or the commands everything so it's what I use as a default this image starts at 35 megabytes versus 5 of Alpine so I'm curious to see how would be an Alpine setting up with everything um when it's finished after all the services if it would be much smaller [Music] I mean for sure it will be smaller but the price I would pay to learn more stuff more commands in my case it just doesn't pay off what I'm doing in Ubuntu image I mean in the docker file in the build I built the Assets in node container right it's a multi-stage so then after that I take that output deleting node modules locally and after that I install PHP dependencies so lots of spices paired if you don't install these in the deployed image and even so this is based on sale so it even has client for postgrey and MySQL and I don't know how to make it much slimmer I don't know it's something we can for sure discuss No Evil saying seems good in reality it doesn't change much it is merely a swap for apt get install for the APK app yeah that sounds about right you know what happened before uh well right now I discovered something more something else I mean whoa for instance in the past I will show you kitab.com Portugal the website yeah for example in this project we are running uh um [Music] where's the docker file here it is so we are running chromium puppet here for the browser shot it's the package to take screenshots of stuff to generate PDFs or images of websites and so on so for example this is something I would I would feel comfortable installing in this container right now I also found there's a browser list [Music] image that Puppeteer connects through websockets and it does the same job right with this image but I would ask if I had to install something like this like I'm used to doing a normal VPS would that be easy with um the Alpine images what's your experience even besides that it should be pretty similar if not equal yeah that's about right that's from my experience I I try to keep it simple I mean if I would need the if I would feel the need to make it as Slim as possible because I were doing kubernetes or something like that um yeah so it would make sense but if I would need that that would be a different case because I I'm not using it so yeah I don't feel that need so he was also agrees multi-stage is amazing evil used to use whoa whoa used to use Debian distros for Docker files but all pine Works quite seamlessly yeah why not I have to try it someday Okay so back sure so [Music] these Docker compost dot prod actually it will stay in the production folder because right now we will change it to production but this production was a copy from the previous folder running in a single container and we've made some changes or I've made some changes in the background while offline and we are going through them right now so what were those chains oh before running seeing the changes let's see what else is happening in today's setup so we have this Docker file to build the Inspire service we are giving that name it's a restart always and we are mapping an environment file so we're not putting it inside the container we will map it in the server we'll map some folders to start it to storage uploads and so on in logs from laravel we are adding this container to a web Network and we are putting some labels that allow to Define configurations for traffic check previous episode please to find out in details we are running MySQL with a volume for persistence pretty standard web Network redis we don't need anything fancy also my SQL is not it's also not exposing a port to the outside world right all running inside the Private Matter private Docker Network same with redis is also not hosting not out in fact no container at all is exposing the port it's traffic that is exposing the parts and through these labels it will route the traffic to this service in this part so that's it so there's also traffic running and all that configuration needed to run so yeah let's change this to multi-container so we can see some changes they opened in Docker file let's see what what changed so we removed supervisor we don't need it anymore [Music] it was a slight change because I added the steady prefix not to mix the stuff that we will believe so everything is the same with nginx with PHP and I'm guessing with the Quran is the same yeah just like before so I re we removed or we are removing the supervisor configuration we also don't need that anymore uh deleting that file [Music] so project file ownerships and permissions they keep the same to work in pair with protection and also we added something more this will run as Forge user this acts as a documentation in we are instructing Docker that this container is running services in these two parts and this is It's running in two parts and why is that because this container might run as nginx or my Trend as fpm PHP fpm so depending on that it will expose a different port and we will see when we will run Docker PS we'll see that in the ports mapping section for instance we can see Inspire was built only with 80 before right expose 80 that will be yeah so before it was exposed 80. so this is why Docker is telling us hey this container listens in Port 80. we are not mapping anything to it like we are here mapping any traffic from any host into Port 80 of that container in the 80 of the outside world but it's saying hey I exposed something in 80 so it's what this line does and we created a new file start container which is a bash file we'll see that in a moment and it's the entry point the entry point is the entry point has to where it says it's the beginning of the program right so when we start the container we go into this into we will run the program here in this starting point and any commands that we instruct will be added after the start container if we add more arguments in the command section okay we have Reuben Mooring hello welcome keep it going friend well thank you Reuben let me know what what's your framework of choice or language of choice but [Music] um in fact I really do love laravel but it doesn't matter right it's just a tool I also love others and I can see most likely you are here because of Docker right but let me know what's here the framework or language of choice maybe we can do stuff with that I'm not doing only lauderville right so and I enjoy pretty much more Technologies thank you for the for the inspiration so.net and Dot net and node.js yes I'm just joking Reuben says yeah uh yeah I know the feeling well uh I do have some I have a container running.net.net core in an Ubuntu running with a dll of uh some Portuguese software it's called phc maybe you know it so I'm I need stuff from that dll and I'm running it in a sidekick application and to the to that software and I need to run dotnet code and I do it right and node.js yeah of course I love node yeah that's cool okay let's get Back start container yeah let's go one by one so from the top we also change something in nginx default configuration and what was that it was that right now um any files PHP are having to be passed not like before because PHP was interpreted by fpm of course but it connected to fpm through a Unix socket which is referenced as a file and here's the instruction but now we are using HTTP TCP connection so we are declaring go when to interpret these files pass it to fpm colon 9000 means foreign nginx will receive a request it will come in into the machine through part 443 it will go to traffic then for traffic it will go to nginx and because it's not a static file that is served by nginx needs to go to fpm to be interpreted so instead of going through a file because now they are on different containers right it will connect to a different container on Port 9000. okay and why is it called fpm because in the docker compose the name of the service is fpm so this will be the hostname in the private Network so yeah this is why this line we have to change also in www.conf we made a change for in the offline while offline and I instructed fpm to listen on Port 9000. because well I didn't comment this I should have um even so it over did an override right so yeah silly me but of course I can even delete this line because we're not using it anymore but uh yeah I will leave the default file the default that was before just commented and I'll instruct to run import 9000. so that's why these nine thousand okay what's more start container so let me check status we've been okay renamed we change the folder name yeah so Docker file we've seen www.com engine next default it's here Docker file yep supervisory D will be deleted so yeah we got it all covered and what's in start container is instead of having the command to run in a in the docker compose we'll just leave it to start container file remember from Docker file yeah if nothing is said Run start container so we'll go to this file and it's a bash file but it's a bash file it's a special project you can go and check it out thank you Adrian to for your script it's very easy to put instructions to run very similar to a composer script or a package Json with scripts but it's flash instead of node or PHP running cool so we name a function and what this does is it will run our function with providing all the parameters it will run all to provide the arguments we have provided and if we didn't provide any argument it will run default so default in turn will run help will output the available functions so let's run a start container it's not there but there's also a task file which is the same structure so here I can see what commands inside similar to Artisan command cool so if nothing is said it will run this but if I were to run a start container web server it would it would run this command so basically the supervisor Services were moved into this declaration right if I want to run web server I'm gonna run this command and this will be the command running in Docker process ID number one in the container so it's the process that must be healthy for the container to be alive that's it and now let's repeat this for every service of supervisor so the worker will run this command fpm will run this command which is configured not to demonize right in somewhere in the configuration check previous episodes and well there's a still wouldn't take care of crown here it is I left this preparation in Middle it's it's still not complete but pretty Advanced right now so it's also running KRON minus F to be in the foreground not to be detached because as you remember Docker has to have the process running in the foreground if you detach a command in a container it will stop and stop the container if the process stops so yeah these are some changes that we've done so let's look into the big thing now how did we do the docker compose in the offline when what I did in the Offline that we will introduce now uh I'm thinking if I should do it put this in another screen and bring the changes or I'm just going to bring it yeah I think I'll do that so our compose dot prod we've seen five minutes ago it has these services so yeah traffic will do the routing websockets with Society red is for kiwis and cash my sequel for database of course and we add Inspire and Inspire is the name of the application it's available open source I still have to organize everything but of course in the end of maybe a couple more episodes I will be ready to organize everything put timestamps in the videos and blog posts and whatnot so what's happening here we'll make a great change so these Inspire service let's remove it from Services okay and let's put it outside services [Music] yeah let's do that what what will we do next We Will We Will instruct Docker hey you don't know what this is but don't worry you don't have to worry about like this and how can we do that we will start with x dash this means that I don't know yeah whoop we will start with x dash the name of the service and this means that I was just checking for ident identation so let's check that this works that Docker is not will not complain I will leave the DPS [Music] get back into local computer and let's run Docker compose Dash F docket compose dot product demo a file that we are editing right and config and sure enough it didn't complain and that's it I'm I'm not sure but I think if this was not to exist it would complain right immediately yeah so this property Inspire is not allowed I don't know what you want so yeah and why are we doing this because we'll take advantage of a Jamal or yaml feature that is called a pointer I mean I don't know if it's called a pointer I just name it like that it's a reference pointer kind of stuff you know programming and memory allocation slightly if not it's just something to avoid several copy pastes so instead of copy pasting these four times I will make something I can use and repeat these four times just typing once okay and I will put in front of the object declaration a this symbol sorry I don't know the name in English amp send I I don't remember sorry it's the something we've seen company and friends the that end commercial so and I will call it base laravel up and what is this the point that I will use multiple times and it's something I will use to run oh Evo is confirming Ampersand he believes so yeah thank you evil um I was thinking amps and yes something like that thank you thank you okay so using this I can now reference by zlatable up and where I will reference that all of these will take place so I'm we're going to use that so that we can make a fpm nginx worker or more workers and Crown containers and declare all these containers using the same base because it's it's essentially what we're doing we are using the same image to build a multi multitude of functions web server fpm worker cron all under one Docker file and of course under one image or service so yeah let's see how we could do that so we have X Inspire and we will now redeclare the Inspire Service as before inspire and right now we will use this notation um left hand signal the less than signal colon and star and base laravel height base laravel up you see even ID is making the autocomplete I didn't know this for lots of years but yaml has this function so for many years I've been using Docker not aware of these and yeah I hope if you don't know it you learned something if you are just starting yeah we can do this in jaml and it's native jammo it's not a thing of stalker so what is of Docker is this convention x dash it's nothing related to for Jamal this is just a name String now this is a special from jaml yeah we can use references in pointer so what we have here right now it's exactly the same as before we have the Inspire service which is uh using all this configuration and what we're going to do is to bring the specific to the web server thing so labels it's related to the web server only container so I'll bring it to inspire okay uh what's more build is the same for all containers for every container also image also the restart policy also volumes and also networks so yeah think we will make more containers with all this configuration and we just tweak a little something okay so before labels I want to say the command we're running it's going to be web server I will use the other notation for array it seems more I don't know it's a command so we could put it in like in the form of an array like for example with traffic when there are so many each of these it's an argument right to the command after the entry point of traffic but in our case we just use one or two simple words so I will use this notation you can do an array in jaml as you wish so yeah that's it uh web server will be added to after entry point so the command for this container will be start container and web server in front of it yeah that's that's what it means okay what's more let me check [Music] could yeah I think that's it so this is dockercompose dot prod that is running today live and that's it let's put it to work like this so let's put it live again and see if we have everything working Moment of Truth how much time we are in 55 minutes so let's go let me check our task file did I leave something here yep so no I've been doing with Git pool right yeah not the private repository so it's pretty simple I will just hit add commit and starts Docker deploy level for protection video right so I'm gonna push [Music] right I'm gonna open below [Music] a tab or a split pane for the production and I'm going to go inside select write user apps inspire and yeah so let's run git pull and now I need to run prod compose so DC Dash F docker compose not prod yamo app Dash D to detach and test build I want to build before bringing this thing up and I want to remove orphans if we drop something but I don't think so you can check these commands from previous episodes and yeah I want to build remove version and I'm most likely sure but I would just want to be explicit let's first recreate so any container of the they will be recreated again this will make my sequel to recreate and remount on the same volume so also the other ones the I'm I'm pretty sure if we build if any container is need to build it will renew right so I don't remember from top of my head so let's see what happens we never built this so we are not taking advantages of caches because right now we removed supervisor remember that there's the place where Supervisor was so the layer is different Docker is rebuilding so let's give it a minute [Music] maybe less so it already built JavaScript oh no no still building Linux there's our steps okay and yeah we've seen recreating Inspire I don't know if you saw but you can go back in the video and you will you will see that re Inspire because it was rebuilt it was recreated the container and that way the all these others were not touched so let's see if all is still working so it was go Viva well it's not running so what happened so let's run Docker PS and Inspire latest is restarting so there's an issue with this so Docker compose follow so what's happening hmm so this is not good let me check let's go into our dashboard so with a dashboard nope what was the name is that dashboard Dash go Viva also 50 50 chance I got it wrong of course dashboard Dash go Viva hmm so let me check of course something had to go wrong so dashboard Dash or Viva dot Princeton oh right um now I remember we have to uncomment the stuff if we want um to turn on dashboard not insecure dashboard allowed not in the port so it has to go through traffic [Music] through traffic it will also run over the middleware so let's change that let's turn on traffic dashboard push let's hit pull let's up again don't need to build it I want to attach the output also I want to see it so it's recreating traffic because we changed the configuration so Inspire Traffic Service Inspire unable to find the IP address for the container Inspire Inspire one find the IP address oh it's traffic never mind yeah so traffic could not find inspire hmm okay so I think it's a different problem so I'm refreshing now I want to remind now we have the traffic enabled stop this and I want to try to remember the password so I wanna where's the file so debugging life right amazing Okay so suppose where's the traffic file traffic dot off yeah it's user Forge well okay so I think I got the password right sure so I will end comment for 1880 I will allow it in securely traffic I'm gonna go hit push foreign I stopped it because I did Slash app and stop right I didn't detach so silly me I'm gonna refresh and of course we are in so everything is successfully traffic wise so oh but of course there's no Inspire we have the websocket server and the dashboard right but we don't have Inspire because it stopped so Docker container vlogs Docker compost I mean vlogs Lord can I specify the service so host not found in appstream FTM oh sorry guys how could this work so sorry hey we wanted this application to work just with nginx so out of my place right so we need to do also the service for fpm so what of course a PHP needs something to interpret the PHP itself so nginx will not do that so we need to do something else running through fpm and we're gonna do just that and we will add the fpm command and if you remember well we go in Docker file start container and then fpm and what that will do it will run fpm 8.1 that's what's going to happen so hope it's a little bit of luck this is what we were needing so let's add fpm service oh also let's make the Inspire service depend on fpm so that only when Inspire FTM when Inspire fpm only after inspired fpm we will bring that inspire right okay so let's get pulled cool and let's bring that up again whatever [Music] the appetite if we get pushed we did not so let's push oh yeah now we have website and now we see we have an external service that has just started right so let's check our website again and still not working see let me see okay let's see what's the problem now so locks inspire host not found in Upstream fpm oh right because my call to the service Inspire fpm yeah I want to call it just fpm I was deciding this before but then I would have to call Inspire fpm also inside the nginx cone right because no no the default website yeah this fpm words it means it's the host name so what I also could do is call the service Inspire fpm maybe it will be more explicit Inspire maybe there are multiple Services of fbm in the same server and you don't want to mix those but even so Docker compose prefix with not allow me not allowed to mix it up but will explicitly Define hostname fpm that's it so like this this configuration will also still be valid and we have to use fpm as a hostname not Inspire Dash fpm and I think we could also use extra hosts not really sure so we could use Inspire and also fpm well also fdm would not be usable in a multi-pps thing so what I'm gonna do I don't I'm not really a fan of having to change this file foreign but also there's darker compose prefix so [Music] fpm in-depth network from Docker compost other one would not be so yeah I'm gonna be specific because this nginx default is for inspire so yeah it has to know that is for inspire yeah I'm happy with that for now so let's go let's go fpm service still we're doing that and let's hit push from local let's hit pull right and let's again bring it up detach so things have changed and with a little bit of luck oh no we have to build because the engine XD file is different now remember so yeah we have to copy that again so let's build we have to bring it up but build it before that's it because we need that copy to happen again this copy this one right stand already a little bit of luck and now we have a new router just came in whoop and it's stopped so let's check logs again host not found in Upstream inspired fpm whoa now let me check let me check inspired fpm should be the Epstein all containers are in network web what happened okay let's be patient and yeah let's go check it out inspired [Music] which containers are running so they're all also always restarting right [Music] how can I finish this foreign [Music] [Music] [Music] also today is not a perfect day to be making it much longer so I'll try to divide a little and if not let's go within five minutes and of course we'll continue um trick I think Monday I will be a really good day yeah that's it [Music] can be going on [Music] all right [Music] I'm gonna go with myself I'm not sure [Music] let's use the hostname [Music] it makes no sense to me but in the example I've done before it's using that I don't know why removing a dash would make it work but I'm just gonna go with it so don't need to rebuild just to What minus d let's first recreate no reason why only with that bring it up again was not found oh it's still looking for the other name I do need to build I guess you were screaming at home with me well not exactly now knowing but let's see let's see what happens well if it doesn't work I'm really sorry guys but I'll have to finish for today that's what happens see what happened Walton's player is not found that stream fpm how is traffic I need to run like 3c6 3c6 can I run Docker so I want to run in Inspire I wanna exec Inspire Rush yeah it cannot be restarting so I cannot run it Trend I cannot go inside I wanted to go inside to check for to check network configuration inspire [Music] hey evil welcome again had to leave a bit but I'm back what are we doing now well um I'm having an issue [Music] because the service Inspire did you see the thing about the yaml separation let me know if you caught from there if you still catch it before you still caught it before well if not I also if yes I think the delay in the communication it will be faster if I explain again we can use in Docker if you use x-9 it will ignore that thing it will let it be there yeah so we use this reference Docker will ignore it in the yaml native thing will allow to use that reference so I declared redeclared now Inspire using that the pointer to all of these configurations and I'm running web server meaning it will run start container and then web server it depends on the other service [Music] yeah that's nice thank you uh not this file start container so yeah the web server will run this command and you'll be running nginx yes process ID number one fpm the worker and the Cron so um having maybe it's my I'm tired so better programming will do it better um this container is declared with those stuff also the labels right and Inspire fpm is the fpm of course [Music] same base definition from the pointer thing and the issue now is that Inspire container in is not able to find Inspire FTM in the network right nginx default finds fpm 9000 as the proxy pass [Music] and right now it cannot reach it the service cannot reach this service so so yeah not good so Inspire logs user directive makes sense only if the master process is running with the Superuser Okay so we'll pick it up that later right now post is not fun it's just warning all not found host not found in Upstream fpm so yeah evil uh is asking if I can if we can uh reach the container with that declaration uh also we couldn't I've done this after later I mean we will delete this and the inspired fpm would be the name the service name is the hostname so we I would also change it here right and yeah that's it is the fpm container oh wait wait Inspire fpm is quitting is also restarting so there's an issue with that also that's why it's not finding right nice so let's watch logs but also from inspired FTM unable to create process side [Music] oh ouch I know what's this in this Docker file we are running all is everything as Forge and we cannot of course we can only run the worker command as Forge not to run it as root yeah I deleted this in middle I shouldn't have so crunch is declaring to run with Forge user exactly so it will not have access to that socket and it will not be able to run so I think we just solved it so I re-ran inspired fpm so yeah it's ah sorry so inspired fpm that's the name for the service same and the same here so it will be the hostname inside is Docker Docker compose Network and if all is well with a little bit of luck will be finished so let's hit push we have to take care of the worker we need to use gozu like to do the commanding naming of other user but we'll do just that so we pushed it we will pull it so if the build goes well with its own user and runs with the service definition user oh also yeah I mean yes of course I can declare the user outside and compose right yes I want to use the forge user to run them worker commands right so that the logs and all of that stuff are available from all in the non-privileged user at least that's how I see it should be then so let's bring it up while building yeah we're pretty close right now I feel it so let's push that extra mile maybe 10 minutes more will be done thinking I really have to leave but now I see it's so close okay so everything is recreated let's watch our traffic container it's all goes well yeah there we go we have a new let's go right ahead like crazy refresh and the photo well yes it's working again I delete don't touch your running system right I just deleted that out of nowhere and I shouldn't have done it so yeah if I were to dockerps everything is running and right now we have two images of the same thing yay evil is throwing confetti cool so uh we're running two images of inspire two containers of the same image only these is running web server and this is running fbm cool so yeah let's check everything is running of course it is right let's vote for Saturday it's right in the line over here let's vote okay and sure enough why shouldn't have but it didn't yeah photo but it was you didn't do the real time why is that let me just check websocket connection yeah it's time everything is well I don't know what happened [Music] ah I know what happened why I know what happened if the worker is not running so that's why the the job of sending the broadcast is not running so yeah we'll do that right now you cannot expect to run it like before if you didn't put it like before right Evo is mentioning next Improvement friend e2e end-to-end tests in its own CI service yeah why not why not we have set that up in uh Cyprus if I don't believe I've done that in the past um also dusk and what was I thinking ah what do you refer with its own CI service um I was going to tell you about drone it's the one I've been curious before I've used Jenkins gitlab GitHub beat bucket but I'm really curious to check about this drone everything works in Docker everything is Docker so yeah you can do whatever you want check it out whatever you used it did you know it let's finish this oh you've used that as well so cool maybe you want to join someday on a live stream and show it working I just use it two or three times and it just works yeah that's all we want things right so let's bring up the worker and we'll use the same base image and let's friend worker and with the user Forge nice so we don't need to use gozu I don't know if it's installed or not even so yeah we would would have to put gozu it's them um sudo not sudo but to do su Command right to do in name of other user but for the containers yeah but it's not needed because Docker compose will add dash dash user Forge to the command before running it in default goes well it will also work and let's bring back our cron also [Music] you'll have to check that let's run the crown so Crone is also running it's already declaring for users so we don't need it we I think we can't even do it because then you will not be able to impersonate the other so he was commenting more oh yes then with AWS integration I believe the Drone CI and code if I remember how it used to work it was some side projects lost just for learning but we can go for the challenge of setting it up from from scratch yeah that's for me it's a done deal let's do that always fun for sure for sure let's for me let's just schedule a date and let's go okay let's friend cron as the another container Cool so if all goes well we're going to commit in the push we're gonna pull from the server and we're going to bring things up again now we don't need to build also not for creation so notice that now we have one two three inspires four inspires of course one whoops where's one and two and three and four working Chrome fpm engine X that's it so let's see if all if they are all up most likely Savage as one vote more now and yeah everything is up 25 seconds oh no no no no start container c c is crone let's see what's going on locks Empire crown no locks so oh yeah look up yes restarting again right so we'll see that later let me see if the worker is working yeah the worker is working so if all went well we'll be able to see now the live updates duplicate whoop not pin pin and we want to duplicate this tab we're going to bring it to the side and we're going to go to results and sagarish as these match votes and let's vote one more my favorite is arts and I from Lidl and the following Well yeah if you noticed it went live update so let's vote from my for my preference now handmade beer from handcrafted beer from Little it's a it's not from Lidl it's just it's sold in only in the supermarket in Portugal so there's about one vote take your pay attention to the purple Mark and I'm going to vote in the fall went well yeah live update so this means that the worker is already work working so let's do something else now uh say we don't want one worker or we want different workers then we were to go into our start container file where is that yeah say you would want a different worker you add more queries you would come and say for instance worker mail and another worker for I don't know um HTTP requests so yeah you that dash dash QE I think it's like that QE HTTP if you if we had set up more than one query right so mile or um reformat or resize images and conversions and whatnot so we would need one more service another more service but before you do that if you're thinking to do worker one worker 2 if you want multiple workers for the same QE that's not how we're gonna do it we'll take advantage of um Docker compose a function which is scale so let me remind how the how do we do that post scale let's inspect Docker PS and what happened Docker compose were brought up a container worker right and you see Inspire it's the name of the folder where we're running Inspire worker is the name of the service and then you see dash one it's an incremental ID so we'll just make sure yeah we want more workers of that so when we are bringing up a compose file we will add one argument Dash Dash Kyle and the argument will be inspire occur equals five so I wanna I want this service with five containers and I would want another service with other amount of containers right so I will just re-up again and if all went well now we see Inspire worker was brought one two three four five times so if I were to Docker PS I now have five workers how cool is that right and if you yeah so this is just five processes if we go to Docker stats oops Docker stats we can see each worker it's taking around 30 megabytes so yeah this is nothing it's not even giving any trouble of course it's one single VPS and yeah it's not a problem it's not like we are having multiple virtual machines it's nothing like that it's a container so it's just a process let's create stats and we are having troubles with Cron why is that we have problems bringing up Crown let's finish that so cron is not going well why is that we can go inside container and run a second process just like if we were supervisor kind of thing let's debug this so Docker compose Dash F prod and let's bring let's run exec not run exactly let's add exec in the service Inspire Bash and we are inside the Inspire container and I I'm going to run cron minus F to see what's going on and it shouldn't have any problem it attached and is running so what's wrong what's wrong with crone I think I'm running a little behind on scan on time funny enough we are taking care of KRON and we are out of time from file will run as large and command why is it failing okay PS yeah Inspire latest always restarting why C7 C7 for logs no locks any ideas evil why these Docker container would not stay up let me see do I have Google yeah me too so I was testing this before in this train before I don't know what can be wrong one two three four five inspired brush so it goes no yeah it goes to forge crunchy foreign user and yeah it's here no no locks if we're saying wasn't following and of course asking for logs and nope no logs I'm inside the Inspire container if I were to Output logs for that container it just comes empty from before okay so maybe let's put a command reverse right or even route console will be faster info inspiring code yeah so these will put to the output so let's [Music] let's file [Music] into base path file and a file called I don't know manual ZZ manual not txt I don't know you want to put instead of put together pen right and we want to append a dough and let's append the time I think we can do now right format y m d I don't even need to die so hour minute second and we'll add a low in the time of friend in a zz manual file I want to see it below when I release directories and yeah HP art is an Inspire this is a command and we want to run it ah evil is asking best rank the command manually that's run well I think so let's run Inspire every minute so we can debug this right [Music] so PHP Artisan Inspire locally [Music] check this is the manual here it is and yeah hello and the time were to run it again it would append something oh I need to add a End of Line right okay so let's run it again whoop and sure enough if we run it we are adding lines okay [Music] okay sorry I was running in this uh reading a another message so running command manually let's check Evo in the server so let's get that commit no I added ZZ manual file so git RM minus minus cached ZZ manual file nice I will delete that not even putting it in git ignore no need for that so because we'll delete just that oh the commit message is not true it's not right anymore pull and let's we need to build again new code right so [Applause] that's the spill see what happens let's clean some stuff for example the traffic we will comment again we don't want dashboard enabled and for sure not in debug mode uh not debug mode but 8080 Port mapped and insecure debug mode is something else that we could do for extra messaging okay so this is taken care of cleaning up let's go back into our server it's recreating Services nice okay so let's run Inspire Bash HP Artisan of course if we were to LL there's no ZZ file so if we run PHP Artisan inspire sure enough we now have a zz manual we are it's as root so it's not good even so not the problem so we are clean the command Works let's see if we were to Crown minus f if everything goes well I will open a new session SSH into the machine change to forge user go into the directory inspire go into the container maybe history also yeah 156 I'm not using the number I'm just pasting so I want to run Docker compose with the file prod I want to run I know I want to exec in the service Inspire I'm an exec Bash so I mean LL and sure enough we have the manual file so the command is running well 2037 8 47 pm that was 20 seconds ago I guess yeah so in 30 seconds we will see a new line over there so it should be running well and I wanna let's just double check so cut it's easy manual 2047 the time 15 seconds oh gosh two hours the minute has passed like oops not fight like yeah so if all went well let's cut and yeah we have two lines and the file of the permissions Forge [Music] so yeah everything should be just fine this runs well in with supervisor and you see we're in cron Dash f as root and everything gets well so any ideas even [Music] if he's not here anymore okay so let's stop this I'll exit and most likely I will just finish this and continue in the next episode to close it up I'd be really happy to close right now but why is it restarting oh Evo is still here okay uh is just thinking so everything went well everything went well if we go inside another container which is the same system foreign all goes well so start container minus Dash f I don't know let me check what the internet has to say this cron command keeps the container running [Music] no it does not that's the problem that's why it restarts but if I were to run it Crown Dash f in a given already running in another container here it's attached and it works and we have seen that just few minutes ago yeah you were here right so it works like this but not when bringing it when brought up by docker so when running from compose it will just keep restarting [Music] and no logs from the service so I'm not knowing what to do cker want to run yeah how to run Crown inside containers you know it seems like I was already here CMD Kron so he was saying something at this I guess he's typing something he meant is there anything that keeps the process running yeah the dash f okay I can do that he's saying to tile minus f so it will bring some logs to the Quran log let's do that so what's keeping it up is the dash F directive right so it's but if it it will not detach to Randy's right I think I can do is just use one Ampersand right and it will detach this one and run the second one yes exactly Dash death keeps it running yeah that's the stuff friend it works just well inside supervisor so I was expecting to be the same thing so double check oh I did almost at 9 00 PM I have to close I really hope we can do this before night thank you so how can this sacrify working if we just come on [Music] you know [Music] the container at stalker bringing the container up and as it runs web server root will also run this [Music] Docker file is running as root right not yeah so it should be able [Music] to stuck around aha he is putting the the crown from the host machine running a command yeah but that's not what we want to do I mean it could also right using ground within your containers yeah that's what we want to do so cat cut on Top Root as this is a root run bash that script yeah it seems okay that's what we're doing [Music] Chrome minus F that's what we're doing nope so evil wait a second you are doing the crown Dash F inside the sh right yes I am from what I recall there might be a few situations where the foreground is not kept as it is running an external script what if you do Crown minus F directly in the docker compose just for debug yeah why not so I would have to run not that not in command but in entry point so I will override the start command thing and we'll do it here minus f right we would override the thing in Docker file and it will run current minus f okay that just might work so yeah we're already debugging crown push exit this let's hit pull we just change Docker compose so we don't need to reveal let's just bring up the thing again exit this session yeah it worked people thanks man nice where is the Crone I mean yeah cron minus f up seven seconds so Docker PS is running 21 seconds 23 yes I didn't know this I haven't set it up so yeah cool so it was not running in foreground when running inside Bash that's curious well but it works for me perfect so let's remove Quran from the wash even fpm we can now yeah worker I will leave here because people might want to put more workers and this will be just fine yeah I'll leave the details about versions and all the stuff here just Quran minus F we are let's keep it here as it is so it was commenting probably with the script signal that was not being forwarded don't recall the term oh that makes sense but probably it was starting another shell so it didn't redirect the signal well that makes sense I don't know to confirm or not I don't know that so well there is a way to redirect it when calling the script but don't recall it at this time makes sense yeah I've seen some crazy Docker images not using supervisor but something else to just one bash file running lots of stuff yeah from hiroku build packs yeah thank you so much evil we are complete and on time 30 seconds before 9 pm in Portugal so yeah there you go uh Docker PS in the server all services are up and we have lots of stuff let's bring back again the scale so the scale service so I don't recall if there's a scale in Docker compose possibility so inspired worker scale no I don't think so let's just double check okay compose scale is that so there's carty doctor compost scale yeah it's via clay or via file is there a possibility replicas yeah I don't think so service one five service two six that's what we're looking for I don't see any other way other than I do believe this exact command helps in that which exact command uh evil yeah I don't see a way to do it in a compose file we have to Docker compose scale service name equals numbers of instance but I think this was moved inside the other so if I were to Docker compose scale already I think it was removed or not darker compose scale yep I think it's outside it's a composed style inspire worker you E5 yeah unknown Docker command composed scale yeah what we do is when we bring it up when we bring it up we bring okay Inspire worker 5 scale of inspired worker is five we wanna detach and we want to remove orphans so yeah let's finish with that so Evo sent a link uh yeah you can send on Discord if you want I'm not seeing it on YouTube chat [Music] you can call whatever command you need to call in your Docker file with the exact command before oh yeah I think you mean Docker compose exec and Command right foreground together [Music] so I think these guys running container with name cron and viral variable and whatnot but he is running from the host system here right look for an exec in that page okay one exactly ah executive okay yeah let's try that I I would prefer to make them tidy under the compose start container thing cron minus f I will change that and we'll bring back the command Cron [Music] foreign let's bring it back up [Music] hit push get pull bring back again with sky with five workers amazing recreate Cron [Music] let's see if it stands running up yes okay cron is the top one at last in a second whoa restarting again it's restarting again so no luck yeah it was a nice drive what are they saying here yeah I'm not sure why it doesn't work this tutorial is also using yeah different distractions pretty store but Quran is Crown bash is wash right [Music] I guess we'll revert the thing and call it a day of course you can explore that later [Music] no luck but we tried huh let's bring Crown minus F will delete remove it and here let's bring it back to entry point cron Dash f and let's just call it today if I can Crown get push get pull and let's bring it back up Inspire worker five we have five workers and everything is up we have four seconds of crime just to be sure when it's filling that up again whoop talking yes sure enough it kept running okay Evo it was a nice thing we got it working not exactly under a bash file but yeah who cares right it's just a tiny detail of course it would be preferable but yeah no issue at all so right now let's close this session let's just recap we now have these setup in place we have a level application the under the green stuff the green rectangle we have container one for fpm one for engine X 5 for the worker and one for cron all these under one VPS and served through traffic so maintaining SSL for the web requests for the websocket requests and redis is running in the private Network as also has my SQL this is recommended to run in a different server through a private network but in this example we're running it just a moment we are running this container in the same PPS but it would be advisable to put in a different server and detached of course from outside world uh we could go in with a jump server but that's a story for another day we have completed the mission thank you so much evil if it wasn't for you I would have quit before and yeah this is amazing thank you and yeah do you want to say anything before we leave thank you I guess we can yeah we have just called it today it's perfect [Music] and what about next steps while I wait oh he's saying all good good stream thank you man I hope speaking to you soon and for everyone else hope to see another one soon oh yeah for sure thank you we'll speak soon uh next oh we have done this today Docker production with one container per service so next time we'll be deploying with laravel Forge in Docker so most it's gonna be an easy one I already have the blog post for that deploy applications within level Forge so here it is we'll be using this last production setup just following these steps will be pretty simple and quick hopefully then I'll also want to explore one tool deploy with qualify it's an open source tool to deploy stuff with Docker is more it has just recent I spoke with andras the author [Music] and not sure if just right because of that or not but sure thing but in a few days there was Docker compost support it's more focused essentially in node applications not service by service but yeah we will see this but now it supports the docker compose it's pretty cool so let's see what comes from there so maybe if we can we start thinking about something with drone.io why not let's make a collab if you are still up to it and of course I want to keep this as a surprise but um there's plenty more content to do with soccer and all the services that we can services in pre-made pre-built images and lots of stuff we can do in amazing content coming on I hope you will enjoy it okay so this is it for today thank you so much once again hope to see you soon also okay one more the delay in YouTube is ha it's so long that seems good need to research it again but sure thing well yeah okay if not thrown something else let's just uh do stuff right if you want to explore something new for you we can also do other stuff but I find it curious to work with true yeah cool guys so thank you so much evil everyone at home also watching people who came people were watching after the recording thank you so much see you soon and as always happy coding ciao
Info
Channel: Patricio On Code
Views: 2,475
Rating: undefined out of 5
Keywords:
Id: 2fDD0qp-iKc
Channel Id: undefined
Length: 128min 21sec (7701 seconds)
Published: Fri Nov 18 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.