Set up LAMP using Docker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so today what we're going to do is talk about creating a lamp stack with docker we already did this previously using Alpine and we're going to talk about some of the pros and cons and getting started with docker as well as just an introduction to what docker is and how its code basically operates so this is the slide that we previous introduced docker and pod man and what containers are essentially using the images from a docker website you can see that docker essentially container Rises or sets apps in their own ecosystem or their own environment runtime environment and it does it using its own sort of daemon or service that runs the top of the host operating system whereas if we were running virtual machines every virtual machine has an entire guest operating system of overhead to run multiple applications now we're just doing a basic testbed the virtual machine may or may not be the way to go but with the Aventa with docker is it's very scalable and you know if you run past a few containers or whatever it's very easy to leverage what you've done from one container to another container as well as the host operating systems kernel itself so it allows docker to be a little bit more scalable and also very fast and very easy to set up so let's talk a little bit about that so what I'm going to do now is I'm going to go over to this file manager now what this is here is we're connected to an SMB share which is now we're gonna run the environment but it sort of shows you sort of the layout that we're going to be looking at so in this SMB share we go up one there's a soccer lamp Ducker LAN P remember lamp stands for Linux Apache my sequel PHP in here we have this docker compose yamo file or yml file so let's open that with etc so we can sort of see what this docker compose the animal file looks like doctor compose is an easy way to set multiple containers within a single file so what it does is you essentially claim a single version on the file once you have that version then you'll have your services set up over here each file or each I should say a container gets a name so you can name this like my sequel contained webserver contain you know I'm just going to call this webserver just for simplicity sake we have PHP my admin just like we added in the Alpine tutorial so essentially what we're going to do is set up the exact same configuration but all of this is scripted all of this is within the same file now when running docker compose I think this X is a typo and save this we're running docker compose you need to make sure that docker is installed so let's exit out of this we'll go over to docker so this is an overview dr. you can see again it has container and it manages images containers leverage images we can talk a little bit about that and how that works in just a moment but essentially once you have an image it gets downloaded if you wanted to create multiple containers leveraging the same image you can so that's where docker sort of really consolidate space and sort of decreases sort of workload overhead which virtual machines can't do because they run whole individual operating systems by themselves then it can also manage the network and also manage data volumes all this can be set up in the services themself if you need to learn a little bit more about installing docker you can also just go to the docker docs and we can just type in selling Dockers so get docker and stall docker and then docker can be run on Mac OS Windows or Linux with Mac OS or Windows the approach is more dedicated for desktop users or developers people who need to set up an environment quickly so it oftentimes includes docker compose out-of-the-box for setting up with docker Linux you need to install docker compose separately if you want to use compose because docker can create containers in multiple ways and we'll talk about that in just a moment but if we're using docker compose so we have this setup what we're gonna do is are going to follow this we are going to also create a docker file so what we want to do is in our darker server or the server that's running docker again this can be your desktop PC as well what we're going to set up this kind of subsystem so we're gonna have one folder which can be docker lamp which is what we have here just fold it over here we're going to set up this lamp contained this is going to be the folder which we then access for the build inside the builds we're gonna have a docker file docker file looks like take a default program [Music] justice this will talk a little bit more about what occupy but essentially it gives us the ability to do a few more tasks which we can't just handle directly by running the doctor compose and if you have this sort of build call here then you need to have the daka file and it will look for that build inside this lamp contain folder so we'll talk about that in just a match but what we're going to do is we're going to set up three directories so let's do that now let me s this H into the server okay so we have a couple folders here we're going to make a new directory we're going to go into that directory and now we're going to make another directory this is exactly the same as what we have here this Lampkin came so we're going to go and contain then we're going to go inside lamp contain so CD that contained we're gonna make another directory called data okay so essentially at this point we have the same kind of directory stack that we just did are already had previously set now what we're going to do is we're going to be this docker compose the animal file so I'm just going to highlight the whole thing press control-c inside here I'm going to use Nano which is my command line text editor of choice we're going to type docker compose yml okay so we're going to essentially create this file then we do ctrl shift B now the thing to be careful about inside these animal files is making sure that the spacing is all homogeneous and what I mean by that is all the indentations I had run into this problem that's first trying to create this image or this runtime was this facing got away from me by accident and if the spacing is it 100% homogeneous for example if you start with a spacing of say two spaces then the next tab in or the next space in or whatever subset of that in the animal needs to be two spaces these - zero are these these lines are just one space in and then one space for the rest of the command you need to be very strict about that because otherwise yamo won't really understand exactly what you're doing version 3 tells you what version of docker compose you want to use I think version 3 is still sort of the default standard right at the moment although I'm sure there's newer versions available as well but version 3 works quite well for this particular set up what we're doing is we're taking an image a docker image which is called my sequel 5.7 we're setting a password for it so this is the root password for this my sequel container again we're just calling it my sequel path PW PWD we're also setting telling it what ports it should run on so we're setting it saying the host port just 3 306 this would be the host port needs to route to the docker port of 3 306 so we're just mapping that exact port number on the web server we're doing a similar thing but we're building it and by building it it allows us to slide load additional variables via the docker file that we just showed and I'll talk a bit about a bit more about that in just a sec we're assigning a volume for this web server so we're saying okay the default data or where you going to look for the data for your bar WW HTML and again this VAR www HTML and Debian and in neukölln - is where apache gets the the web directories so if we have something like a home dot HTML it'll look inside bar www HTML for this home dot HTML which would be the home page for say like a website or something we're setting the ports here so you're setting up the ports file and again we're mapping the host port of port 80 to this port 80 we're linking the system to this my sequel contained so we're linking the two services together so this might contain service that we called forward up here is getting links to web server so web server knows that it needs to rely on my sequel and depends on essentially a saying wait for the my sequel to start up before you start up so that way we make sure that the database is already available before we start the web server and login with PHP my admin again we request this image PHP myadmin my PHP myadmin this is a docker image call it essentially goes to docker hub and we can see that over here in docker hub you can search for things like PHP my admin and you'll get a list of various images that various organizations or parties put out we're calling in the first one PHP my admin again this is also what we're getting the my sequel image so we have my sequel there's also options for say like mario d DB my sequel my sequel server or something or other some of these are by users some of these are by official organizations so you can choose which one best suits your needs what we're gonna do is call them my sequel i did do a little bit of work with the mario TV one but unfortunately it wasn't liking working with PHP my admin so i'm keep holding back to the my sequel image in this case so that's why we're calling this my sequel and then we're specifying the version of 5.7 then over here we're just insisting that on the PHP my admin letting it know that the the PHP might have been host maps to our database we're saying that the database root password is the same as what we're setting over there and then we're saying that the port that PHP myadmin needs to use for connecting to the my sequel contained is this 3 306 so that way PHP my admin knows that it needs to connect over that port and then for PHP myadmin we're actually setting a different port so that PHP myadmin is going to run over port 8080 rather than port 80 and we'll show that in just a moment so we're going to set this up on this remote system there might be some firewall things that we need to change but we'll sort of work through that and now we're going to press control X say Save Changes yes okay that's the docker compose now we need to go into CDE lamp I'm sorry I put that in the wrong container let's move docker compose the animal we're gonna move it up a directory so we're gonna move it into home this tilde sign right here is a home slash docker lamp so we just have data here so now if we went up one directory we have the docker compose CML so it's fine now we go back to the land contained and again this is just mapping with the file management that we have so the compose sits outside of where we then build the environment which is specified in this lamp containing folder now we're going to create a docker file so again we just press nano I'll just say caca file it has to be capital D it has to do this exact thing and there's no ending or you know file and disgusted by it just has to be a pure docker file which essentially is a text document so we go in here and again we're going to take this docker file what this does is it what we're defining is this docker file which comes from the build so webserver builds so we're building a new container and it's going to look for the build requirements inside the stalker file and then what we're saying is you'll notice that the my sequel contained and PHP admin we request an inch okay so we told docker where to go get this image we said we need the PHP my admin / PHP myadmin image will reset when you the my sequel version 5.7 image we did not do that in here because we're saying we're going to build it and when we build it we request in the docker file so when we're requesting the docker file we say from PHP 7.0 Apache so this is running an Apache web server with PHP it's an image which is specified as such if we looked for it in a docker hub we would also be able to find it so you have this PHP and there's many versions of PHP services so we're just specifying that we want this one the one with Apache so we can also look for that here so you can see this is the Apache Ubuntu or Apache whatever so we're just specifying which PHP image we're looking for going back to the docker file we're also telling the docker file to run this command so there's this docker PHP xtxt install this is telling docker to install an additional PHP image or PHP repository so we need this my sequel I again I think we talked a little bit about this during the Alpine setup but the my sequel I is essentially a vehicle in which PHP or our website can then connect to the my sequel database it's where we create queries and is where PHP can make connect to the the my sequel DB and we're also going to tell it to expose port 80 this is going to make sure that we have access to the system access to the web server via port 80 so we're doing these three things in this docker file so we're just going to copy that control see inside here this is running on our webserver just do ctrl shift key so we have that save exit' okay so we see we have the docker file we have data let me also just check the read/write permissions on theta it's fine so we have this docker compose here lamp contained so now what we're going to do is we're going to as root user or using sudo because this is a Ubuntu machine say sudo doctor pulls up and then that's going to run all of our docker compose commands enter the password for your root user aha my doctor composed itself and again this is one of the things you just need to make sure that you're running in Linux so and go ahead and install this real quick and I'll put links to all of this and in the notes on the blog what we're gonna do right now is very quickly install docker compose to make sure that we can actually run this and it's pretty quick and again for if you're running Mac OS or Windows I do believe this comes with the docker installer the default docker install docker also has an install package I believe it's called docker toolkit we should also include dr. would compose plus the docker runtimes so now we can just do docker compose help make sure its installed yes it is and then we just scroll up through the commands the suitor doc goes up so now it's doing this okay it's not finding the images right now so it's automatically downloading them it's downloading the latest images of PHP my admin and all these other images that we called so that would include the my sequel it also includes the web server which is the PHP 702 Apache image so we're pulling all this down now you okay so the system built there was an error because the port defined is already being used by another project so we can check that with docker you can run this command PS it shows all the running containers and we do have a container already using this port 80 which is where the problem lies so what we need to do is we can run the command docker container stop sorry stop and we can save this docker lamp webserver one control ship see control should be can't stop that then controller stop we got we got this other one my sequel contained and again these are names of the docker containers if we put this full screen and be a little bit easier to see but when we do the docker sudo docker PS which shows running containers I have this other troop command container which is already running it's also already using the port 8080 which is the reason why the PHP might have been failed so you can see this cannot start external connectivity applying for port 8080 failed or it's already allocated so what we're going to do is we're going to stop my signal contain as well stopped and what we're going to do is Nano docker compose and change this port from 8080 to 81 so in open court and we're going to try bring this up again now it should be a lot faster this time because the first time was downloading all the images so we sped through that in post-production and we're going to bring this up again it should be very very quick because the images are available if you want to see the images you can do doc sudo docker images LS sorry image LS and we can see we have all these different images now the nice thing about docker is that we can have as many containers as we want if it's a common image that we call the image doesn't need to be re-downloaded or duplicated in any way so the image size can be expanded upon or extrapolated to contain all these other images so for example like hello world or true command or PHP my admin or PHP whatever all of these are images which we can then leverage and work with so what we're gonna do is we're gonna bring this up in docker compose up recreating okay all that looks good and again this particular server I can show you I'm also association to it over on this terminal as well we can just check the IP address and the IP address for it is this 190 168 1 2 3 . to q7 okay so if we go over there we actually probably won't see anything it's forbidding you of access which is true because we don't have indexing turn on for that default but what we can do is create a very simple website let's see deduct lamp lamp and data now we're going to create a index.html it's gonna be HTML oh and do a header it says hi there can I save that so index.html is the default sort of home page for Apache so we can refresh so we get hi there so that works the other thing we can do is do a nano PHP info make sure PHP is working now again we'll just run the straightforward PHP you so a very easy PHP script to make sure that we're running the correct version of HP so we just go over here slash phpinfo dot php' and we get the info so PHP is running that's great so essentially at this point our web server is running the other thing we can do is check the HP line men so we set at the port 8081 there's PHP my admin you know the route we set the password and the password as we defined it was my sequel no sorry yep and now we're in we can create a database this is using the route we can just create a new database again we can do like pizza order or coffee order create you have a database we can create a table we can enter sequel commands we're good to go that's essentially all we need to do on a docker stack so I took a little bit of time just because we gotta download all the packages but very similar to what we did with Alpine we enabled a lamp stack so we have Linux Apache MySQL PHP all running within docker again if we want to see what's running you can just do the sudo docker PS you can see everything that's running in the docker containers you can see for stuff for containers right here so we have p.m. a contained that's the p8 PHP myadmin we have docker lamp web server we have docker lamp my sequel contained this is essentially the lamp stack these three containers I also have this other true command container drew command is a management platform from IX systems to manage multiple three and a Centurion s devices so I have that running as well and you can see here all of this is running together each one of these is completely independent and there's other things that we can do from the docker as well in terms of managing it so we already showed the docker image LS that shows what images we have again this is a very useful tool you can sort of decide for yourself whether or not it fits the bill I think in our Alpine image or Alpine VM where we created our own dedicated lamp stack on top of Alpine we came in at around 1 gigabyte of total size or total use storage space after we install all the packages I think it was around 900 something this is actually a little bit larger just from the images and doesn't include docker itself that being said if you do need to scale and you do need to have many services or many containers or many test environments docker is kind of invaluable for us ability to run firstly on any platform so you can install it on Mac OS Windows or Linux if you install it on Mac OS or Windows it essentially runs a small Linux virtual machine which then runs stocker on top of it if you're running on Linux the service just runs on top of Linux and if you want to create like really quick services or you bring something up or bring something down you can also manually go in and do just sudo docker container stop and then you can enter the container name so I'm going to stop like say p.m. a contained we could stop it right now just by doing p.m. a contained because we did use docker compose the other thing that we can do is inside this composer time which is essentially logging what happens in docker compose and so on what we can do is just Co control C if we want to bring everything down so doing control C does like a graceful shutdown or older different containers and then from here we can also do different things we can also do dr contain there's a whole host of features like we can also rename so we can change the names of containers for docker compose that would it be useful but if i say i wanted to rename my true command container i could name it like TC command i'm not sure this is gonna work for me all its running let's do sudo yes so you can see the name instantly changed for a true command so you can sit you know once you've created an image you can pretty much change it to whatever the ID is a unique idea with docker then assigns to it so docker essentially plays by the ID but it it knows it knows the names it knows essentially from doctors point of view would be essentially a nickname so that's kind of just a quick overview of docker again the other nice thing that we can look at is i can run a top come in and you'll notice here we can look at the memory so we have this looks like about 257 megabyte s-- used right now by the system i was to bring up this lamp so we're restarting the three containers again the PM a contained or the PHP might have been the web server with the Pachi plus PHP and be my sequel if we look at top now we can see we're at five hundred twenty six megabytes used so it's it's a very small amount it you know you're essentially getting three independent systems self-contained systems if you were to run this even with Alpine our Alpine install we use 512 megabytes of RAM total for the system and if you are using something like Ubuntu which is what these stacks are running on right now or Debian or something and you wanted to run each of these containers is three separate virtual machines the memory overhead would be much higher you'd probably be looking at at least two gigs of memory per system just be able to run it smoothly in the back end so that's another huge advantage with docker it scales very well it might not be quite as small as say running everything together as services within a single Alpine environment like we did in the previous video but in terms of scalability flexibility and manageability docker is quite nice it's also a little bit more straightforward installed particularly if you're using Mac OS or Windows so these are just some of the quick things that I wanted to show and again thank you all very much for your time appreciate it
Info
Channel: Open Source Tech Training
Views: 5,862
Rating: undefined out of 5
Keywords:
Id: svlcIIp-S9w
Channel Id: undefined
Length: 35min 8sec (2108 seconds)
Published: Wed Jul 01 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.