DOCKER TUTORIAL - CS50 on Twitch, EP. 23

CS50 · Beginner ·☁️ DevOps & Cloud ·7y ago

Key Takeaways

Explores Docker for containerization and deployment of applications

Full Transcript

all right good morning good afternoon good evening depending on where you are in the world this is cs50 on twitch my name is Colton oven and I'm joined today by David Malin also up cs50 good to see everyone again it's been a while yeah it's been a while since when was livestream that you were under no I was good December I think we played Zelda laughs that's true it was not as much of an educational stream this today it was very educational what game are we here to play today I'm all set to accrue some point it's a game called docker I believe it stars a whale of some kind of yes indeed we have a bunch of people that work in Europe celery I see a lot of people have tuned in already nice to see some familiar name we're almost at the magic number of 50 we have 49 viewers currently but oh and after what happens after 50 and then we just get tons of just tons of money of money yeah we have a lot of people in the chat using a lot of regulars I shouted out a bunch of people in the chat but thanks so much for everybody who's joining damn Darrell Babic night we have Bill of cures Elias Ashley Brenda mister Frigg who I think is a new person could you snipers we V eyes o TV I think Isaac's evil over the first I'm impressed you can pronounce all these so easily I've done a lot of practice at this point and Kloppenburg thanks for joining another regular for Sun Life sort on JP guy you know but yeah just absolutely ton of people we got a first-timer here one Jocko OTS yeah I don't know yes yeah thanks so much for the follow they oh they followed up before the stream as well nice hello Ellis orsa Ellis or so yeah that's a new person as well than adamantine bipartite what's up David and Colton what's up thank you yeah that's the first time I've seen that name that's a woman yeah we got a lot nice to see everyone who met Osmond another first-timer from Adam yeah I'm gonna Amy this is hello whip streak 23 there we go another 52 oh we missed the 50 we blinked and it was gone we did yeah so what are we what exactly is darker that's what we sort of spoiled what we're talking about today it's not actually a game no I'm sorry so tune out now if you don't want to learn something really interesting though technically so docker is containerization your looks like your laptop oh we're not plugged in Oh apologies I should have if Colton's gonna tell some jokes here for just a moment to hear about the guy who forgot the plugin is yeah here we go let me go ahead and today's lesson will be about how to change your display preferences here we are going under scaled so as to do 720p which is an actually very high resolution but for our purposes of streaming technical content makes it all a lot more readable on the screen Oh Brian's actually the chasis hello Brian ooh 20 years oh nice please send all of your questions to Brian you who is here from cs50 steam yeah Brian I'm sure knows a lot about docker too all right so let's begin again so docker is containerization technology but what does that actually mean well let's rewind a little bit normally when you're running software it's on your Mac or your PC or your server or somewhere else and you have installed whatever operating system was installed when you bought it or when you first set it up Mac OS Windows Linux or whatnot the problem though arises in a server-side environment where you want to run multiple applications like cs50 has a whole suite of web apps we have we have the cs50 sandbox these 50 lab if you started tuning into cs50x 2019 we have help 50 in style 50 and bunches more so all of these apps have their own dependencies like certain software and libraries and frameworks that they need and frankly not all lots need the same things and so in yester here only five plus years ago we cs50 used to have a centralized architecture for all of our web apps we had what we're called vhosts servers virtual hosting servers running popular web server software called apache and what we would do is we pretty much had to find the greatest common denominator among all of our apps and actually install on those servers every library and every piece of software that every app might possibly need the problem of course is that eventually you run into incompatibilities one needs this version another needs that and now you're just out of luck and if something breaks in one app it's not isolated from another and so one app can take down the rest so docker ultimately is about isolating your applications from one another and so this is on your your webpage there what is a container I'm guessing that the whale and the boxes on top of the whale are sort of like a representation of this idea of containers indeed indeed we can pull this up if I enhance this image up here so docker is a company that also makes and contributes to open-source software which is also called docker and indeed you can see those little boxes represent those big we call them containers that really big shipping containers that tractor-trailer trucks generally card around so it's actually pretty cute the whale is instead the ship and it's holding up the containers and it's really cute if you want to go ahead today even install docker at least on Mac OS the first message that the software will print for you is we are Whaley grad glad to see you but I should say some folks out there might be familiar perhaps with virtualization software now for instance does anyone used VMware or parallels or other such tools those are that's certainly been around for a while a long time much longer than docker has and I know I've definitely used it quite a bit yeah and we used those too but with virtualization software or virtual machines or virtual machine monitors bunch of different ways to describe essentially the same thing you would have to run you could run multiple operating systems on your same computer essentially each OS in its own window the problem with a VM or virtual machine is it virtualizes the entire hardware the CPU and the memory and the disk and the files and everything so it actually is a lot heavier weight like you have a lot of redundancy if you have Linux in your can your virtual machines you have that and as many copies of Linux running and installed as you have virtual machines so dr. part of docker does it sort of mitigates that resource use on your machine indeed indeed I've so I pulled this up in advance one to learn what docker is and to to actually show some of the fun pictures that they have that actually do paint a nice nice picture here I think if we scroll down yeah indeed so here on the right this is just on docker comm /resources / what - container on the right you see an artist's rendition of what a virtual machine is at the lowest level you have your hardware your infrastructure like the physical servers the blue bar above that is hypervisor aka virtual machine monitor aka VMware or parallels or other software - and then on top of that conceptually you have maybe Windows installed and Linux installed and maybe Mac OS but Apple does not make that easy otherwise known as your guest operating systems and on those guest operating systems you have your individual apps each running ok so now if you look to the left what what seems to be missing for instance well there's no virtual machines separating the apps you know all running on this in sort of the same bucket container is applications Aero that's what that's yeah exactly yeah each of those apps is a containerized application which means it's each app is using docker docker is now the software beneath them that makes all this possible and notice you only have one operating system so you run for instance Linux or something on your own base computer and thanks to docker can you now share just one other operating system friends if you'd like across all of those applications and moreover and most excitingly if all of those apps ABCDEF are all running Ubuntu Linux version 18 well then what you'll have is one base installation of Ubuntu and if app a and B needs slightly different software they're just gonna be layered on top docker supports what's called a Union filesystem so if we both have apps that we've written using Linux but I need a library called foo and you need bar will share the same base layer but for you docker will layer bar on it but for me docker will layer foo on it but still have that commonality and we both need two different versions of Ubuntu does it do similar similar it does you go a little lower level but then each of us has our own copy of a bump do fifteen or sixteen or eighteen or whatnot and then yes those are isolated from each other okay pretty cool yeah so it sounds like in fact there's not a lot of the bulk unnecessary oh yeah associated with running multiple VMs indeed thank you I know we definitely have a bunch of messages here all right well let's catch up on these what if we talked about apache in here people had asking what is docker I wear Dockers I think it's a clothing brand try to do this in code recover fifty five people there we go this is what we'll be talking about that yeah okay see city fashion for someone asks is it a simulator or an emulator and they're talking about docker um it's technically neither it is in and of itself its own technology yeah I mean it's closer I think to a virtual machine than to either of those where those are implementations truly in software of just one specific runtime but emulator is pretty close to virtual machine there's just a little more sophistication I think under today's VM because you're virtualizing an entire architecture and the operating system on top of it they're saying David sir is fun oh nice sorry eight all the views today left looks like hosted VM and the right is a type one VM is before sunlight said okay on the screen they're trying to saw cs50 offline but needs doctor could you at some point in this video explain that's a perfect segue actually let me just so folks can play along at home if you would like I'm not sure Colton and I alone can provide technical support for everyone who wants to try this but if you google docker download odds are that will lead you to this page docker comm slash get - started and it's actually pretty straightforward to get docker up and running on your machine so what we did in advance of today is I'm using a Mac right now you can click on download for Mac that's gonna take you to a longer harder to pronounce URL and if you scroll down here you'll see a number of different versions of docker for instance docker desktop and you can scroll through follow these instructions here and actually go about getting this up and running on your own Mac and it looks like let's say here looks like they're gonna make you download like you got to login these days because they want to get your email address then you can go ahead and download docker for Windows or Mac OS or Linux for free so if you're free to do that behind the scenes if you'd like to play awesome you can use Windows education if you can get that through school we're talking about Windows if use Windows you need the pro version of Windows is that how maybe like CPU virtualization no it probably has to do with licensing honestly and charging more for the fancier support no witness education is very very generous when windows pro is darker used for web apps this is adamantine bipartite it can be I mean docker is agnostic to what you do with it which means that you can any you can run any type of software inside a byte container inside of docker which is the very specific product we're talking about so yeah in fact to all loops see every this true stone I think every one of cs50 s Web Apps is in fact doc arised or containerized to say more generically so yes and then we have some other apps that are not web apps like I think is check 50 check 50 is also docker rised yeah yes oh and do we want to point people to the sous vide dive we have a seashore let me pull that up so he all Suman on this URL if anyone wants to see some of cs50 zone documentation you can go to cs50 dot read the docs comm I plugged it in the okay nice Colton just pasted it into the chat and you'll see documentation for all of our stuff related to docker and more and in fact I'll pull these up very specifically soon but someone mentioned the offline IDE earlier if I go ahead and scroll down to let's see here IDE cs50 IDE at the bottom you'll see a mention of offline and these instructions will walk you through the process of starting to get your own IDE up and running locally to be fair if there's a little bit of complexity and I definitely plan to get more comfortable with docker as you do that because you can do quite a few more things with it as well server on it is a better installing dr2 a dedicated server or using AC LOD instance which is a VM also like more layer will be better in the context of performance oh I mean anything running on bare metal so to speak without a virtual machine is gonna give you somewhat better performance because you got to pay some price for having the virtualization with that said it's a little annoying to install thing on bare metal so to speak these days because if something goes wrong or you want to reinstall you have to wipe the whole thing whereas installing things on a VM isolates it from everything else so it really depends on your own I would not be worrying about performance just yet if just trying to learn docker and you want an experiment do what is easiest and honestly do it on your own Mac or PC assuming the hardware in your version of the OS will support it docker is pas or IaaS docker enables IaaS which is a funny acronym these days for infrastructure-as-a-service these are things like AWS Amazon Web Services or Microsoft Azure and Google compute cloud but it really is a piece of software you can use on your infrastructure so it's to do anything higher-level platform as-a-service is something like Heroku docker is not a web application like Heroku is it's lower level so it's related more to IAS cool and then with docker containers be a similar concept to Ubuntu snap sort of I don't know too much about bunch of snaps we're still just using apt-get install and such on our setup but my understanding of snaps is that it's a cleaner way to distribute individual software packages correct me if I'm wrong docker and containerization more generally is about container rising an entire operating system and everything they're in so it's probably fair to say that docker has a bigger product whereas snaps I think are more isolated to individual client side applicant client side individual pieces of software containers give you a whole environment okay I think we're all caught up on all the questions here if you want to maybe start diving into yeah absolutely so let's go ahead here and let's get started so here again on docker comm slash get started is where you can probably download this for yourself if you would like to play along but I think it's perhaps most fun if we just dive in by way of example see what's going on and then actually understand hopefully like how we built these various tools with cs50 we have a few different use cases for docker we run all of our web apps using docker in the following way we write our web app locally on our macro PC we push our code to a github repository or any repository we then automatically build the code installing anything we want but we do this by way of what's called a docker file it's just a text file which is a configuration file that just specifies line by line what pieces of software do you want this application to need and therefore install for you so why don't we go ahead and take a look why don't we go ahead and open up a terminal window here and I've got another one ready to go when we get to another topic - and I'm gonna go ahead and run vim which is a command line text editor here and I'm gonna go ahead and open up a file called docker file actually let's do this let me go ahead and make a directory called twitch just so that we have somewhere to work I'm gonna go ahead and now run them on docker file so I've just got an empty file in which I can do really anything I want now now you would only know the syntax for docker if you actually read the documentation or follow it along here at home and I'm gonna go ahead and say something like from Ubuntu 18.04 from I've capitalized that's a docker command Ubuntu is the name of a docker image a snapshot in time of some base installation of Ubuntu and the colon 18:04 means that's the specific tag so canonical the company that makes Ubuntu and the whole ecosystem out there that uses Linux installed for us into a file Ubuntu with a whole bunch of packages and specifically tagged it this is release 1804 what that means is that my own application whatever it is I'm building here is going to be based on Ubuntu 18.04 so let's go ahead and run docker and see what happens if I go ahead first and run docker and type PS I'll see all the containers that are running on my Mac which at the moment are none I don't actually see anything docker itself is running on Mac OS I can see this here with the logo in the top and this is where the menu is and you can see docker desktop is running if you're on Windows or Linux your menus gonna look different is gonna be somewhere different altogether but the fact that it's running is a good thing and that's why I was able to run docker PS it queried the underlying server software I'm gonna go ahead now and say go ahead and docker run a specific image and I'm gonna go ahead and actually know what sorry I'm gonna go ahead and build my current image and say go ahead and build this thing here call called dot which is my current directory isn't it which folder this isn't my twitch folder so there's really nothing interesting going on here yet because all that file had the dockerfile was that one line but notice what happened so as soon as I ran that step one of one was from Ubuntu 1804 docker went ahead and pulled so to speak from its library of free images and installation of Ubuntu that image happens to be broken down and you only know this by looking at the results into four layers so to speak I mentioned the Union file system before so odds are one of these layers is like the very first pieces of software that are installed by Ubuntu the next layer it goes on top of that then the third then the fourth and each of those has additional packages or files most likely be accurate to say like one or one or the first two layers to be like the kernel of the operating system more or less the same amongst well I don't know if it'd be the same amongst versions of Ubuntu but it dependency a bit more of this one I add to the docker file in just a moment will see exactly what each of these lines corresponds to so this is just a sha-256 hash which is like a big seemingly random string that uniquely identifies this version of the image you'll see that my status was successful it downloaded a newer image because I didn't have any for Ubuntu 1804 and it successfully built this hash so these are the last what ten or twelve characters of a longer sha-256 hash that uniquely represents now my application I'm in at which folder if I type ls' the only file I have is docker file so I've got nothing interesting in this code in this folder yet but I now have a unique image that I can now run so I am on Mac OS let's see if we can see this if I do you name you'll see that I'm running darwin which is the codename for Mac OS if though I do docker run IT and I'll come back to some of the command-line arguments later that particular unique identifier let's cross our fingers and oh my god I now am inside of Linux running on my Mac now I I feigned surprise I kind of knew or hoped that would happen but indeed if I type ls' now you'll see a whole bunch of folders that are not on you Mac or your own PC they are now local to this container and so curiously excuse me I seem to have this base in the Linux file system but you can actually mount files from your own Mac inside of this container so let me take a step back I'm gonna go ahead and do I think exit which gets me out of that now if I type you name I back in Mac OS and if i type LS now there's my docker file and none of those blue folders are actually there but if I do this and I'm gonna have to remember the syntax if I do docker run - I T - V dot : let's say MNT for mount i don't quote me on this just yet and then paste in that image nope volume name is - shorts let's see of all note maybe it's capital V nope docker run okay we're gonna run docker run help to see how to mount volume find a mountain of volume mount directory I'm David's blanking on how to do this properly let's go ahead here and do this once more dr mount damnit no are the fun of the live coding stuff yeah this is not what I wanted to do volume name is too short okay so here folks we're gonna do docker mount directory since I have essentially aliases for all of these things yeah that's V that's what I want to do so here folks we're gonna introduce you to a website called stack overflow that's what I wanted to do oh I might need to do a fully qualified path now let's try this again alright sorry folks also adamantine bipartite illis or and you Ginter X 9/11 thank you very much for following very welcome so let me go ahead and try this docker run - V splash mount and now - I T and then this image okay I'm sorry it's just I think I needed the fully qualified path and not the dot so that's just me being stupid apologies so now what does this actually mean if i type LS because I'm now back inside of that Linux environment all seems to be fine but if I go into this MNT directory which is a Linux convention for a folder in which you can mount stuff a CD a hard drive a folder or whatever and type LS now you'll see that that file from my Mac is inside of the container which is neat because now I can use Linux on my Mac but still access my files any of my Mac actual files yeah that's a nice thing that some VMS have a little bit sometimes too yeah and now funny enough let's try this now I'm inside of Linux I'm gonna go ahead and run vim and uh Oh what happened to my vim yeah I think s it's not a default program in Ubuntu yeah that's you know for exactly it doesn't seem to come with at least the base image that the folks out there have created for folks to use with docker so on Linux if you're unfamiliar you can do apt-get install and then something like them to install software unfortunately it doesn't even have the cache of local packages so in this world you do apt-get update and that should now download from Ubuntu's web servers or CDN all of the latest indexes of like the software that's available like a DNS server room us not so much DNS it's a package manager apt and it almost puts a dns on your machine that then allows you to fetch a package using a name I wouldn't conflate it with DNS honestly because I think that goes a little too low-level this is like Windows Update or the App Store just checking what the latest software is honestly that's available so now if I do apt-get install vim you're gonna see a whole bunch of crazy messages because vim needs all these dependencies do I want to continue sure I'll type Y for yes hit enter and now inside of this Linux container inside of docker I now have just installed software I'm gonna go ahead and clear my screen just to get rid of this distraction and I'm gonna go ahead and do them now and voila now I'm running vim but notice this if I hit escape and quit out of em which itself is kind of a feat sometimes and now I go ahead and exit out of the container rerun the container and run them it's gone so it's ephemeral it is at least in the way we've configured da core now I have a pristine clean environment but the good thing and a bad thing if you want it to be isolated from everything else you now have a deterministic starting point bad and that oh my god that just took like two minutes now I have to do it all again okay so how do we do it again well let me actually eggs outta docker and in Mac OS just to be clear here's Darwin I'm gonna run vim which is already installed by Apple for me on my Mac I'm gonna open that docker file and now we're gonna create another layer so this from command gives me a base layer with all the default Ubuntu software now I can go ahead and do this run apt-get install vim but I need to be a little smart about this but not yet save it now I'm gonna do docker build dot to build my current directory and you'll see unable to locate package vim does it how do you have to do that applicant update yeah exactly so we'll see that this returned a nonzero code like my build of my container didn't work so I'm gonna go ahead and open that docker file again and I'm gonna do apt-get update and then run apt-get install vim can you do like a semi colon space and then apt-get install vim or without work you can so let's come back to that because I specifically want to see these two runs for just a moment okay so now I'm gonna go ahead and save that let's clear the screen and rerun docker build the dots across there fingers you'll see it's doing more work when you build the container now and you only have to build your containers once unfortunately it and failed again okay because it looks like it's asking for yes or no and I don't know how it would know how to get that input yeah exactly I mean this is meant to be an automated process and yet here I am just expecting it to know right yes from no so turns out you would only know this by reading the documentation or the man page if you actually say - why you can proactively say just say yes to any questions that get asked so let's go ahead and save this clear the screen docker build dot and now notice notice what it didn't have to do a moment ago notice that it's immediately trying to install vim but notice that on this line Ronn apt-get update it's using the cache this time and that cache has a unique hash identifier which means all that work we did last time we do not have to do again because we baked it into a layer okay so some stuff will be ephemeral and that will sort of be saved exactly anything you put in your docker file will persist by way of the file system layers you are effectively creating okay let's go down to the bottom and you'll see successfully built and all the stuff above refers to them having been installed now this unique identifier is different from before the other one I don't think started with f9 so now this is a new image on my Mac so I'm gonna do if I can get this right forget the directory docker run - V for volume users J Harvard twitch : mount but you can mount it anywhere inside of Linux if you want - I T for reasons we'll come back to and then this new hash enter I seem to be inside of the root of counts of Linux and indeed I am now let's go ahead and run vim and it's that and now if I quit exit out of the container rerun the container top random again now it's persisting nice okay solve that problem indeed I'm assuming we could do a lot more complicated stuff than install vim yes you can build entire applications but notice this suppose now that I didn't quite appreciate what I was doing and I did docker build dot oh maybe I need to build my image every time mm-hmm notice but done it's all cash because there's in the docker file exactly and you can see here that every time we had a run command step one step two step three we got a new identifier for that layer and so every one of these run commands are in few others and docker files gives you a new layer that just keeps getting layered on top and top and top would you want to ever make those changes not persistent for example maybe it fetches remotely a librarian that could change day to day yeah short answer yes and the best way to explain that how best to do that if it's too complicated we don't have to know know if you can let me show let me give a teaser of something will perhaps see a bit more of later implicit in a docker file is this last line here and I might be getting the specifics a little off is essentially this command bash so by default if you don't specify a command the docker container is just gonna spawn bash which is a shell that is an interactive prompt for you you can override that so you could do something like by the way at the very last minute do apt-get install - waifu' to make sure you have the very latest version of foo and then go ahead and run bash okay that would be one workaround to that that comes to mind okay indeed let's make sure we didn't miss any yeah let's catch up on any question and it was really good though thank you we have a bunch of stuff up here we just try to figure out where we left off I think this is roughly where we left off so our lxc containers something similar to dr. yeah Aleksey is just another approach to containerization it's not docker it's just a different technology but that too is quite popular sigmund pennies saying hey Lexi is paravirtualized alright that's a word that I've never seen before yeah there's some differences and I'm not good at appreciating that the difference is here I think frankly docker has a really nice and user-friendly ecosystem which is just why I personally gravitated toward it early on cuz we'd be saying if you're an inception things Linux subsystem for Windows and then add donker to that that's right and then you can run Windows and Linux on top of it and Linux on top of inside of that and even Linux inside of the Linux and Linux but you have to start hacking around and make that possible and then your computer just know yeah just that's bad you no need to add too much overhead here no problem we I think you were apologizing on you as well no let me scroll up here the the blah blah common docker volume create I didn't want to create a volume to be clear I wanted to mount an existing directory on my existing Mac into the container but that is another way maybe maybe are actually responding to the other goal you can create persistent volumes so that everything in slash temper slash user local or whatnot actually does persist on your Mac and gets remounted every time certain times I see how the first few lines for running Linux yep and Dave Muse man oh why is the default we could try wipe here we're getting trine and oh sure we'll try this so I want to go ahead and just run docker run again with this command Nano I'm sorry it's not installed VI now is cuz it came with them okay does it have let me add is Linux Ubuntu have any editors that come with it by default well it depends what you mean distributions of a bun two distributions of Linux come with different packages it's later than is well it's more technical so short answer no and let me pull this up in just a second the image that's a made available by canonical or whoever for docker is it by design super super small honestly if you have a server-side environment the goal of which is to isolate the app from every other no human should really be SSA Qing into that container and doing anything with a text editor to be fair probably every one of us if you do if you're if a system in have done this before but you're just wasting bytes and megabytes and just by installing them my god you're slowing down the build for your server-side application probably doesn't need to be there by default that's all that's going on here okay if you download and install Ubuntu on a CD or an ISO then odds are it yes has a text editor thinking adamantine my partner was saying way up above that they were doing all the cs50x stuff they're working on projects nice guys someone else is saying five roman bar i catching up good have probably the hardest one says adam on team he's referring to pset 5 the other same patch just a package manager was apt-get can we see the GUI in Dockers is for sunlight there isn't really a GUI here you could certainly run in docker an operating system that then has a window manager like xfce or something else with a gnome or something on top of it I don't have an X server installed so even though we could install all that requisite software I couldn't without wasting some time pull up an actual GUI but you could do it but for the most part docker is not about giving you a pretty user interface it's about giving you an isolated installation of some OS and some app five versus vim I don't know the difference I'm guessing they're just version differences probably vim is VI improved so it's like the new and improved version of VI and mostly they're typically AI is typically aliased effectively to them so you wouldn't notice the difference anyway these days a new oven is them more MORE okay we're gonna little distracted by text editor debates here I think Superman was saying you don't want to separate the commands in the two layers referring to there are two run commands yeah so that's actually true and you meant I mentioned this earlier when you proposed as much if I go back into my docker file I probably don't want to decouple the updating of my sources list from the installation because those really are one should be happening both together so that when I've updated the list I'm installing based on that list so I'm actually gonna pull this up onto the first line and do something like and and this is better than typically doing something like this because and and these are two separate commands and and it's going to ensure logically that this whole line will only succeed if both the left command and the right command oh if I succeed very much in yeah exactly so this would be a better way and it also creates one layer caches the layer itself is gonna be a little bigger but for installation of software that tends to be the best practice okay streams more users in the super streams cool that's good the educational content assets I don't know I kind of miss playing Mario Brothers oh we're playing excite bite today I was led to believe that yeah okay we old you old carrot on a stick I finished spell check today I think it's just examine your programming way of thinking nice pieces nice Congrats what was that one up here I personally here's a struggle with recover to call Brady primer plus book okay oh nice so you finish speller that's pretty quick actually that's great I want to show off how layers work since I'm and penny I think okay one of the maybe one of the next things to talk about or the entry point yep that's actually a step before the command I think you run off this question yep but this time we have container hi hi from the US and caps hello digi bolts just installed Ubuntu VM using VMware motion I have used docker instead a good question so just to read it a little more slowly David I just installed an Ubuntu VM using VMware on my machine should I have used docker instead it depends if you just want to have a bun to available to you and persist all of its state and just be like a locally installed operating system no the VM is perfectly fine that's what we used to do back in the day with that said I personally have transitioned to using containers for everything they start nearly instantly whereas the pain-in-the-neck years ago to run VirtualBox or VMware on my own Mac or PC so there's less overhead with docker which is super super compelling and in fact in a little bit I think we can demo a tool that cs50 built called cs50 CLI command line interface which Adam is perhaps a solution to your problem or your interest there whereby we can just run a command CLI 50 enter and voila you're running Linux within a split second on your Mac and I go in and out of Linux all the time on my Mac thanks to that tool and our youtube you're typically doing most of your actual development in Mac probably right on the Mac using Linux yeah yeah honestly and why maybe let me add let me even why someone asks no there I mean I like Mac's in terms of like the user interface they're just pleasant to use it talks to your iPhones and whatever other devices you have so it's kind of a nice environment the hardware is great but all of our software runs on Linux I prefer the Linux environment I'm not such a fan of Darwin just because of conventions that they have and so you kind of get the best of both worlds this way I still use my own terminal window on the Mac but inside that window is Linux so David the human uses max and David the programmer uses Linux so you're not as inclined to use a VM to get the Ubuntu interface as much as you have the Mac interface with the actual development yeah I don't care about actual development without meeting all the overhead of a full VM yeah I don't care for you no more any of the other window managers they just don't solve any problems that Mac OS doesn't how do you edit your sources that list without an edit to install an editor Oh without an editor so theoretically you should not have to update sources dot lists because by default from Ubuntu you should have a list of all of the URLs via which you can get the standard distribution of ubuntu software so apt-get update should update your cache of of URLs essentially and if package names and versions and apt-get install will then install those you're only in a pint if you have no text editor and you want to install third party text editor that's in some other repository for which you have to edit your sources dot list file in which case the easiest approach is just install vim or Nano or Emacs or whatever from the standard repository and then go and edit the file but honestly if you're comfy with Linux or learn a bit more about Linux command lines or really this is um bash command lines you can do something like let me go back into the VM cat Etsy apt what is it sources dot D no sources dot lists yeah here it is so here's a line for it let's not do the security line let's do the more generic one up top so all of these lines here just refer to where can you get from Ubuntu's archives more software you could do something like this echo this string on to this is the append operator the end of at c-- apt apt what did I call it sources dot list and hit enter and that would concatenate onto the end of the file exactly that string and with very very high probability will something like echo or cat be installed because they're either built into bash or they're part of the core utilities that are installed looks like sugan has a very similar suggestion here mmm-hmm small links version named Alpine witchdoctor image like five megabytes if I don't remember right incorrectly Alpine Linux yeah I know a little bit about it's five mega but yeah no I mean there's super small distributions of Linux we have not bothered with that because frankly we want access to some of the more popular packages and honestly Debian and Ubuntu you just have so much momentum these days that anytime software comes out for Linux it's almost always packaged for the Deb format so we just use that and the whole ecosystem that comes with it so we actually pay the price of bigger images but it just makes our lives easier we don't have to compile software from source just to get it up and running control our thing main advantage of docker compartmentalizes what runs on it separately as contrast with the heavy overhead of a VM yeah absolutely yeah it's yes much much less overhead which is pleasant lilia via vargas oh I believe is on Facebook is it hello I'm she's joined us on Twitch so hello welcome aboard have you yeah exactly so this commenter here tsukemen alpine is very small yes but it does not contain G Lib C I think I'm not sure about that but I believe you and a lot of the regular Linux software is not supported absolutely on that last point for sure okay GX evolves it does Harvard per divide like sure videos for all of their CS courses not all no relatively few are online Harvard's Extension school does provide some others if you want to type maybe dub dub dub that extension dot harvard.edu but there is tuition for those courses there's relatively few free courses available at the moment via a open courseware for free they also say you're famous for oh thanks for your passion oh that could be about yeah I think it's about you the whole school isn't free which is adamantine that was saying which is but what you just said about the extension stuff you're the guy who lectured about scalability love that video oh nice I like that one too and let's check out cs75 yet see it 75 and 76 are getting a little old to be honest but I would certainly check out if you go to it actually can I type a URL here too so if you go to edx.org slash cs50 you can see all of cs50 is currently available sites and see what's available for free there all right so just getting a set up for the next bit so should we actually transition maybe to CLI 50 and I'm partly for Adams sake for instance so if anyone wants to play around with something that's a little more accessible perhaps let me suggest that you go back to cs50 s documentation cs50 dot read the docs IO and if you look in the menu for the Li 50 command line interface 50 this is just a Python script really that we wrote that makes it easier to run docker commands and honestly this is why I forgot how to run the command before because I always use this which to be fair I wrote so I knew it at one point just not 20 minutes ago yeah so here if you follow these instructions you can install CLI 50 yourself but per the documentation here step one and two you're gonna want to install docker first and python 3.6 because both of those are dependencies of CLI 50 but what I love about this tool if I may say so myself is that we use it all the time to actually develop software and work in a Linux environment with honestly without having to type these crazy long commands that clearly I can't remember so I just run CLI 15 anytime I want to run a Linux environment and voila there's a little more output here because what's going on you'll see that one by default it's using the latest tag called latest which is the docker convention pulling from cs50 CLI you don't have to name your images using weird hashes you can give them more descriptive names so our image is called cs50 slash CLI and I'll pull that up in a web browser soon here's my crazy long hash for it it doesn't have to pull anything cuz it's up to date cuz I got my laptop ready before the stream there's some port mapping going on here we very often do web development inside containers and I want to make sure that inside my container if I have a web server it's accessible on my Mac or PC so these are port mappings so if I have a server running inside the container on 8080 TCP I mapped it Arbor sudo randomly to 30 2773 and then I can actually have multiple web apps on my Mac all running on port 8080 inside the containers but exposed so to speak to my Mac on different ports which is great for development purposes oh yeah because any content within your Mac you not to worry about testing within the Linux yeah exactly you'll see one of the first features we made was printout this string this is cs50 CLI I also changed the default directory in cs50 CLI and change the prompt a bit and we pre-installed a lot of software in advance so that it's all just readily available to you among them them here why don't we spaz forward now let me show you the dockerfile for cs50 CLI so all of these images are freely available as is docker and Python and everything else we've been talking about if I go to let me find my image docker hub so if you go to hub docker comm slash bar for repository slash cs50 you'll see all of cs50 s free docker images and if you speak pick the one called CLI you'll see this interface here there's not too much you can do on docker hub other than see what what images are available but what's cool is that here you can actually see the docker file we made for this image now it's a little cryptic looking and we don't have to go all into the details details because a lot of this is just Linux stuff not docker stuff but you'll see the following this image does not inherit from the Ubuntu image it actually inherits from a parent image cs50 makes called base image which is a generic layer we use across all of our images more on that in a moment user in argh these are just lower level details let me wave my hand at them for now expose is relevant though this is saying go ahead and expose those three ports to the outside Mac or PC just like cloud 9 on which cs50 IDE is based so that's so that we can mimic cs50 IDE on our Macs and PC by default so - just like an Alpine not all software comes by default same on the Ubuntu docker image you don't even get the man pages by defaults because they're blacklisted to save space that's not good for us pedagogically so we go in and put them back essentially by way of this line by unex cluding something that was excluded ok so now we're doing some really funky stuff here using some linux commands to make sure that we are reinstalling them this is a little more obvious here we have now a run line that spans multiple lines in Linux if you do a back slash and then hit enter it's not going to move you to the next command it's gonna let you finish your thought on the next line so all those back slashes just mean this is really long apt-get install line and you'll see there is vim and like dozens of other programs that we or a couple dozen other programs that we use as well okay in the class much cleaner than having on one massive line yeah it's just unmaintainable so here now we use a lot of JavaScript stuff in the class no js' and internally not in the class pedagogically but I wanted to install these tools here one of which we do use in cs50 HTTP server we use in like the middle of cs50 to run your own HTTP server literally we have a few gems in Ruby that we tend to use in cs50 as various platforms so we pre install those here a lot for markdown it looks like yeah I'll markdown related to a lot of our texts based websites here are some Python packages some related to Amazon Web Services these are just comments I made to myself frankly so I remember what these lines do some of our own tools there too yeah you can install our tools for free help 50 render 50 submit 50 and others buy a pip which is pythons package manager under 50 is a pretty cool tool I do we could do a whole session on that one how to make PDFs every pretty cool action you can see that have my notes to self temporary there are bugs or missing features and some of the software that's open source that we use so we fix on specific branches or tags sometimes so that we can mitigate any of those issues and then last thing you just can see that I'm installing some files config files we don't have to go poking around too much but here this is my favorite feature we have a message of the day which every day is this is cs50 CLI and you can see I'm using that echo trick I'm echoing a string this is cs50 CLI and this time I'm just blowing away the file if it's even there so that the only message of the day motd is that particular file and then lastly just like on cloud 9 we're adding J harbor to the sudoers giving it admin privileges as well pretty cool so that escalated quickly to be fair but this was after weeks or months of sort of realizing all we need this to where all we should add this and build and build and build and let me just real quick open up base image the thing on which it's based so we use this with the base image for check50 for all of our web apps for CLI 50 and I think one or two other things as well and that just has even more common software like clang and curl and get that we want across all of cs50 s usage of docker we just factored it out like good design yeah yeah and all together I mean it's not that monolithic no no and it's a pretty nice higher I mean that's what this is we're making a family tree cs50 base images the route we then have cs50 CLI we've got another call at cs50 server which we can perhaps pull up later and then we have a few others that are a little leaner for efficiency and no more view hosts no more vhosts I mean that's what we've gotten rid of we used to have a pair of servers two servers running Apache and an old version of Linux that honestly is still unlike a bun to twelve or something I mean that's the problem too if you want to update your operating system you have to put your entire server at risk because god forbid something goes wrong you've just screwed up your whole system so with containers they are disposable if I screw up a container no big deal exit rerun it and I'm back in business so for folks to playing web apps this is probably probably the future of most companies trying to deploy their business under well at least if they're on their own well probably even on it on AWS yeah I think for the foreseeable future not necessarily docker specifically but like C was mentioned earlier containerization and I'm sure humans will come up with something better after that but yeah these are kind of replacing what were virtual machines for some time and in fact a lot of people are running virtual machines on bare metal and then running docker on virtual machines and if you're using AWS Azure or Google you're running on VMs by definition of how they run their architecture and it seems like good damage control like you were talking about yeah for sure GX evolve looks like they're also asking about C s550s he has 161 121 and 124 that might be a typo no such thing as CS 550 cs161 is operating systems knots of is available through Harvard's X might be available to Harvard's Extension school CS 121 definitely is that's introduction to theory in CS n CS 124 definitely is that's introduction to algorithms and data structures those are at dub dub dub extension harvard

Original Description

Join CS50's David J. Malan for a tour of Docker, a piece of software that utilizes "containers" for making development and deployment of applications all the easier, compared to methods like vhosting of yesteryear and more current methods like virtualization. Co-hosted by Colton Ogden. Tune in live on twitch.tv/cs50tv and become a part of the live chat. This is CS50 on Twitch.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from CS50 · CS50 · 0 of 60

← Previous Next →
1 Hello, World: Hadi Partovi
Hello, World: Hadi Partovi
CS50
2 Content Distribution and Archival in a Digital Age
Content Distribution and Archival in a Digital Age
CS50
3 CS50 2014 - Week 1
CS50 2014 - Week 1
CS50
4 CS50 2014 - Week 3
CS50 2014 - Week 3
CS50
5 CS50 2014 - Week 0, continued
CS50 2014 - Week 0, continued
CS50
6 CS50 2014 - Week 4
CS50 2014 - Week 4
CS50
7 Week 3, continued
Week 3, continued
CS50
8 Quiz 0 Review
Quiz 0 Review
CS50
9 CS50 2014 - Week 3, continued
CS50 2014 - Week 3, continued
CS50
10 CS50 2014 - Week 7
CS50 2014 - Week 7
CS50
11 CS50 2014 - Week 7, continued
CS50 2014 - Week 7, continued
CS50
12 Breaking Through The (Google) Glass Ceiling by Christopher Bartholomew
Breaking Through The (Google) Glass Ceiling by Christopher Bartholomew
CS50
13 Introduction to Amazon Web Services by Leo Zhadanovsky
Introduction to Amazon Web Services by Leo Zhadanovsky
CS50
14 CS50 2014 - Week 9
CS50 2014 - Week 9
CS50
15 How to Build Innovative Technologies by Abby Fichtner
How to Build Innovative Technologies by Abby Fichtner
CS50
16 Light Your World (with Hue Bulbs) by Dan Bradley
Light Your World (with Hue Bulbs) by Dan Bradley
CS50
17 Building Dynamic Web Apps with Laravel by Eric Ouyang
Building Dynamic Web Apps with Laravel by Eric Ouyang
CS50
18 CS50 2014 - CS50 Lecture by Steve Ballmer
CS50 2014 - CS50 Lecture by Steve Ballmer
CS50
19 CS50 2014 - Week 10
CS50 2014 - Week 10
CS50
20 This is CS50 with Steve Ballmer?
This is CS50 with Steve Ballmer?
CS50
21 Meteor: a better way to build apps by Roger Zurawicki
Meteor: a better way to build apps by Roger Zurawicki
CS50
22 Data Analysis in R by Dustin Tran
Data Analysis in R by Dustin Tran
CS50
23 Data Visualization and D3 by David Chouinard
Data Visualization and D3 by David Chouinard
CS50
24 CS50 2014 - Week 6
CS50 2014 - Week 6
CS50
25 Build Tomorrow's Library by Jeffrey Licht
Build Tomorrow's Library by Jeffrey Licht
CS50
26 CS50 2014 - Week 9, continued
CS50 2014 - Week 9, continued
CS50
27 Essential Scale-Out Computing by James Cuff
Essential Scale-Out Computing by James Cuff
CS50
28 iOS App Development with Swift by Dan Armendariz
iOS App Development with Swift by Dan Armendariz
CS50
29 Sam Clark Leads Yale Students on Tour to CS50 at Harvard
Sam Clark Leads Yale Students on Tour to CS50 at Harvard
CS50
30 3D Modeling and Manufacture by Ansel Duff
3D Modeling and Manufacture by Ansel Duff
CS50
31 CS50 2014 - Week 5, continued
CS50 2014 - Week 5, continued
CS50
32 hello, world
hello, world
CS50
33 CS50 2014 - Deep Thoughts - Hash Table
CS50 2014 - Deep Thoughts - Hash Table
CS50
34 CS50 2014 - Deep Thoughts - Binary Tree
CS50 2014 - Deep Thoughts - Binary Tree
CS50
35 CS50 2014 - Deep Thoughts - Scratch
CS50 2014 - Deep Thoughts - Scratch
CS50
36 CS50 2014 - Deep Thoughts - MySQL
CS50 2014 - Deep Thoughts - MySQL
CS50
37 LaunchCode Visits CS50
LaunchCode Visits CS50
CS50
38 CS50 Live, Episode 100
CS50 Live, Episode 100
CS50
39 CS50 Field Trip to Google
CS50 Field Trip to Google
CS50
40 This is CS50 AP
This is CS50 AP
CS50
41 Week 4: Monday - CS50 2011 - Harvard University
Week 4: Monday - CS50 2011 - Harvard University
CS50
42 Week 2: Wednesday - CS50 2011 - Harvard University
Week 2: Wednesday - CS50 2011 - Harvard University
CS50
43 Week 1: Wednesday - CS50 2011 - Harvard University
Week 1: Wednesday - CS50 2011 - Harvard University
CS50
44 Week 11: Monday - CS50 2011 - Harvard University
Week 11: Monday - CS50 2011 - Harvard University
CS50
45 Week 3: Wednesday - CS50 2011 - Harvard University
Week 3: Wednesday - CS50 2011 - Harvard University
CS50
46 Week 12: Monday - CS50 2011 - Harvard University
Week 12: Monday - CS50 2011 - Harvard University
CS50
47 Week 1: Friday - CS50 2011 - Harvard University
Week 1: Friday - CS50 2011 - Harvard University
CS50
48 Week 3: Monday - CS50 2011 - Harvard University
Week 3: Monday - CS50 2011 - Harvard University
CS50
49 Week 10: Wednesday - CS50 2011 - Harvard University
Week 10: Wednesday - CS50 2011 - Harvard University
CS50
50 Week 2: Monday - CS50 2011 - Harvard University
Week 2: Monday - CS50 2011 - Harvard University
CS50
51 Week 9: Monday - CS50 2011 - Harvard University
Week 9: Monday - CS50 2011 - Harvard University
CS50
52 Week 7: Monday - CS50 2011 - Harvard University
Week 7: Monday - CS50 2011 - Harvard University
CS50
53 Week 5: Monday - CS50 2011 - Harvard University
Week 5: Monday - CS50 2011 - Harvard University
CS50
54 Week 5: Wednesday - CS50 2011 - Harvard University
Week 5: Wednesday - CS50 2011 - Harvard University
CS50
55 Week 7: Wednesday - CS50 2011 - Harvard University
Week 7: Wednesday - CS50 2011 - Harvard University
CS50
56 Week 8: Monday - CS50 2011 - Harvard University
Week 8: Monday - CS50 2011 - Harvard University
CS50
57 Week 9: Wednesday - CS50 2011 - Harvard University
Week 9: Wednesday - CS50 2011 - Harvard University
CS50
58 Week 8: Wednesday - CS50 2011 - Harvard University
Week 8: Wednesday - CS50 2011 - Harvard University
CS50
59 Week 10: Monday - CS50 2011 - Harvard University
Week 10: Monday - CS50 2011 - Harvard University
CS50
60 Week 2: Wednesday - CS50 2010 - Harvard University
Week 2: Wednesday - CS50 2010 - Harvard University
CS50

Related Reads

Up next
AWS, Azure, GCP: The One Thing Every Business Gets Wrong
AI Daily
Watch →