Setting up a Digital Ocean droplet with Docker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone it's bobby from big coding here and in this video we will be setting up a virtual machine in digitalocean we ssh into a machine in visual studio code and lastly we will be setting up docker and docker compose so let's jump straight into it [Music] so before i start if you haven't already please subscribe and click the bell so you're notified every time i add a video to the channel and also like and comment on this video because i like to read the comments i like the feedback and it helps me create different content so that's got out of the way let's jump straight into it if you have already subscribed by the way you will know by now that most of my recent videos come with a tutorial on my website this is that tutorial okay so i've got a step-by-step guide here of what we're going to do today and how we're going to get this done so let's jump straight into it oh by the way if you click this here that'll open up this video that i'm recording right now um so if you don't want to read along you just want to watch the video be my guest so syllabus what will we be doing today we'll be creating a virtual machine we'll be connecting to it with a password then we'll be doing it with an ssh key and then we'll be installing all the dependencies in this case it will be docker and docker compose okay so prerequisites we will be using visual studio code there are our other text editors out there like sublime text um i like vs code it's uh all-encompassing i've been using it some time now so i'll be using that but um feel free to use another ssh client such as mobile xtam i have done a tutorial of that in the past if you click this here it will show you how to install it on your machine but like i said i'll be using vs code so if you want to follow along with this tutorial get vs code up and running on your machine and let's crack on so there are numerous cloud service providers out there ie aws ec2 servers you've got a lynode you've got google compute engine however i use digitalocean i've been using digitaloce for some time now i find it very very easy to use and it's very cost effective so that's why i'll be using digitalocean today if you click this link it will take you to digitalocean and you'll get essentially you'll get a hundred dollars of free credit on your account so um be my guest click that link and you'll benefit straight away as soon as you set yourself up and that is the first point you've got to visit digitalocean set yourself up with an account once you've got the account and you can then follow along with the rest of this tutorial so that's the first thing you need to do next we need to click on the green create button and select droplets so this is digit lotion i've already got myself set up this is my dick coding account or demo account if you like we click create click droplets that will open up this screen here i won't keep flicking backwards and forwards i'll step the step-by-step tutorial on here has lots of images and it walks you through and we'll be doing that now anyway so um let's go straight into it you can just keep the defaults for this tutorial um however if you're setting up a production machine and you might just need to think about what type of machine it needs to be we'll be using ubuntu and then you can select the plan this is basically the different power that you want or the difference um memory sizes that you want on your machine it defaults to 48 dollars a month and that is 8 gb of cpu i've got 160 gb of ssds and we've got five terabytes of transfer that's what it defaults to but if you flick across some of these you can go to much cheaper plans that we will um [Music] where are we bringing we'll just keep it as default for now for this for this basic tutorial then you've got adblock storage just don't worry about that then it comes to data centers it defaults to new york now um go with the data center where you are in most of your users are i'm in cambridge in the uk so london is my closest data center um however it doesn't really matter if they've got a data center close to you then use that or you can use new york san fran frankfurt so on and so forth so select write one don't worry about much of the i mean authentication ssh key we'll be setting up in a second anyway but we'll set up a password so we when we ssh it will still ask us for a password anyway so create the root password oh what we're done here what about here i must have pressed enter sorry let's go back on here there we go so it has to be eight characters long blah blah blah blah so make sure you get the right sort of password and uh finalize the create this is the default name of the droplet when it's going to be created you can change that so we'll call this decoding demo add tags we won't bother about that for this demo but like i said if you're doing this in a production droplet then you might want to start adding different bits and pieces you can add a backup so they recommend this so there's a system level backup let's take them once a week and it costs you in this case this is relative to the price of the the droplet itself but this will cost nine dollars sixty cents for the month to do this backup create droplet okay ah that's what i've done this closes that one go back on to this one and there we go i opened up a new screen so once you click the green create drop the button it will then take you to this screen and there'll be a blue line there whilst it's configuring everything out and a nook notification will come up here in a second and it will say something along the lines of your droplet is ready to go if you click into this it will give you the details of the droplet so the image the size the region i thought i clicked that doesn't really matter um decoding so we there's the ip address yeah so we can copy that we'll need the ip address okay so in this case it's point two four five don't worry don't need to blur any of this out because i'll be deleting this at the end of the video so copy that let's go back to our tutorial so we've done this bit we've gone through yadda yadda happy days and we've got to this point here that's it your virtual machine is ready to go can you see that that's a bit better yeah that's a bit about so your virtual machine is ready to go and make a note of your virtual machine ip address as you will need it in a second so now we want to connect to our virtual machine so we need to open up visual studio code on a new terminal or in a new terminal so let's make this a bit bigger for you and we'll bring this up a little bit there we go that doesn't look too bad we will need an ssh key pair to assess the new virtual machine in the new terminal add the following code so it's ssh keygen and it will then generate a public private rsa keypad what it then asks you to do is detail the path where you want these files to be saved now i want to add mine it gives you an example of a path so in my case it defaults to user bobby and there's a directory in there called ssh and within there i've got all of my my keys but i've got a directory in there called demo ssh so we will add that here dot ssh and then we've got demo underscore ssh and we'll call this demo just double check quickly bobby and i can't see the wood through the trees where is it where is it where is the ssh there we go demo ssh that's where we're going to be saving this okay press enter it lasts you for passphrase if you add a passphrase every time you use your ssh um let's say when you're trying to connect or if you use an ssh key for github it lasts you for that passphrase so it's just another tier of security to the ssh key we won't use passphrase on this but you can in your production key there you go and that is complete we now should have there we go we've got it in here so this one here so pub file that's your public key this other one is your private key so this is the key pairs so what you need to do is open up the public key and this here is a massive it's an encrypted key it's very very big so you want to highlight the whole thing by pressing ctrl a and you can copy that we'll need that in a few minutes but not just yet go back to the tutorial so i've gone through all of this here you'll generate a public private key pair you will also be asked for passphrase and there we go is that it you have to save your key replace the ip address right so what we need to do now is open up visual studio code and in the bottom here let me put clear it's not liking that let's get a new one okay so we want to ssh and root at now we want to copy our ip address and we want to dump it there now with ssh in it will now ask us for the fingerprint just put yes and it'll ask you for the password that we just set up now this is the password we set up on digital ocean for a droplet so hopefully you used one that was memorable okay so we now we've now connected to the droplet via our password okay that's what we've just done we now need to add um so we need to save an ssh key to the authorized key i'll change that in the final version use the following code to open up the root user authorized keys file so this is a file that is by default in the root user directory.ssh so any ssh key public key that's added into that file will be authorized to ssh to this server for the root user we can also or we will also be using um that same method for a non-root user so we'll be setting up a user called bobby giving them the right permissions and then adding an ssh key to their file as well so i'm just going to show you how to do both so if we follow this command here go back in vs code and we're cd so we're changing the directory to ssh then we're opening up a nano so sudo nano and authorized keys and that'll then give you the opportunity to um paste in the key so if we go back into the notepad that we opened you just press ctrl a and that will copy everything in the notepad copy back in here and right click and it should appear there you go press ctrl s x that will save and exit so that's all we need to do for root adding an ssh key for a non-root user is also pretty easy use the following code to create your non-root user add non-root to the group sudo set up an authorized keys file and then open a nano to add your ssh key so obviously where it says username star style username then you'd put the username that you want so if your name was fred it would be fred so let's minimize this screen so we can do it like for like okay move that across so we go add user bobby password password okay i'll ask you for a few other bits and pieces just you add them by all means but we went for this tutorial it doesn't really matter but the user bobby is now added we then use user mod sudo bobby and we put g password a bobby sudo okay so bobby has now been added to sudo so now all those privileges so if we put cd go back to the base directory we should now be able to cd into home and when using the add user command it creates a directory in there by the same name as the user so there should be a directory in there called bobby so cding into it we now want to make the ir dot ssh and cd into dot ssh and lastly we want sudo nano authorized keys now open up another nano if we make sure that we just copy this again so we're not copying some random stuff in there right click control s control x so the same ssh key has been used for the root user and non-root user bobby now if you had more different users using different machines you need to add all of those different keys to those files to make it work but for all intents and purposes we have now added the ssh key so we should be able to connect using ssh so like i said earlier i'm using visual studio code so this next part is specifically focused on how to configure vs code to connect via ssh like i said at the top of this tutorial there's a link to how to set up mobrex term and how to ssh to a server it's very very easy it's not very difficult at all but this is all vs code so firstly we need to install two extensions so the first one is remote ssh so in vs code if you click here and search remote it will come up with a whole range of stuff now the ones we want this one here and this one here by clicking remote ssh and clicking install i've already installed it but if you click the install there it would actually install remote ssh and remote ssh editing configuration file that's exactly what you want you want those on your machine it'll take a couple of minutes but get them installed on visual studio code then when this is all installed we want to click the green icon in the bottom left of vs code on the bottom left of the screen click the open ssh configuration file and select the path to your ssh key okay so we'll do that now so bottom left hope you can see that click that and it will come up with this here you can scroll down there's a whole bunch of options but what we want is to open the ssh configuration file it will give us a few options but we want the one for bobby that's the one where we just saved our ssh keys okay so although config isn't there it will be as soon as we click it it is there for me because i set this up as well but yours might not have that so if we go into there so let's just make this a bit smaller you can see i've been tinkering around with this um what you need is uh the ip address so again copy the ip address go to vs code um these ip addresses don't exist anymore by the way i've been just tinkering over the last couple of days so host is demo you can call that whatever you want just something memorable so when we connect to it that host name will appear in the host list which you'll see in a short while host name that is the ip address now the user we've set up route we'll set up bobby we'll be disconnecting via route it's no big deal but if it was bobby in this case you would put um in fact you could just change that to bobby it wouldn't matter because we're using exactly the same um ssh key so in this we would want identity file sorry dot ssh and then it's demo ssh and it's demo that should if i save just double check so host is demo hostname is correct the root name the user is root and the identity file is um dot ssh which is correct and then it's demo ssh and slash demo so remember demo is the private key so that's the pair so the public key goes in authorized keys private key is what you're pairing it up with here so save that and now what we need to do is click this again now demo should appear in connector host so we've got docker test which is this top one we've got demo which is this one click demo it'll open up a new instance of visual studio code it's connecting so that's what it's doing down here it's actually connected straight away sometimes as it does say on here on the in uh tutorial it will ask you for uh in this drop down uh please select the platform for the remote host demo uh click linux okay that's what you need to click and it should then all set up shouldn't have any problems uh it doesn't like white space in the config file so just be careful of that make sure that you've got it all in there correctly but other than that you should now be connected via ssh so if we look in visual studio code it should give me the option to open a folder and then you can put root um if i click ok it will show me all of the directories in my panel there we go probably haven't got any in there ah there you go so this is my root directory so remember we had ssh authorized keys that's what we added in there okay and if we were to connect to let's disconnect close remote connection open up another one connect to host demo and then connect to it'll give us an option but if you delete rue so go home bobby trail and slash click okay that will then connect to bobby and if i open this it will show the uh everything in there that we've added in there so we added the dot ssh and we added the authorized keys happy days so there we go we have now connected via ssh now what we need to do is install dependencies okay so open a new terminal we don't need to actually we've got one open but open a new terminal that is connected by ssh that's what you need to do the first thing we need to do is update and upgrade package information to do that you use the following commands so sudo apt update terminal let's minimize that there we go we don't need this sudo update i'll go about and um go through the processes then you want uh sudo apt upgrade this will take a second or two but whilst that's doing that we'll flick back here so we'll be installing docker compose using curl and docker using docker repository or the docker repository run the following command to make sure you have all the correct packages on your virtual machine so we want sudo apt-get install we've got ca certificates curl gnu pd and lsb release so copy this go back into vs code it should it's still going it's 72 once we've got this next part done we'll be adding docker's official gpc key with the following so they're the next two commands we'll be doing 98 it won't take much longer okay so that's now done um we now need to let's copy this again and we will paste that in there where are we oh didn't like that one second let's just see if it works like this if not we'll manually add it okay well i will have to change that so sudo at get install car already got it ca certificates yeah i'll change this for you well so we got we've got gnupg and sudo get install might like that there we go so we've now got all of the packages all the dependencies that we need so we need to add docker's official gpg key with the following so we'll copy this across go back in here can we clear that yes we can looks like a bit easier so we'll add that we then need to use this command here which will bring everything in we should do there we go that's that done and then we sudo apt update and then we get installed we've got in docker ce docker c cell up cli and a container io there we go is that right update and then we will press that yes okay that's doing whatever it needs to do next uh verify the docker engine is installed correctly by running the hello world image so we just want sudo doco run hello world so that'll work as soon as we've done this there we go so you should see this anyway so hello from docker this is just an indication that it works so if you actually put docker version it should then say yeah docker 20 10 12. okay so that's dog docker installed i said dogger then if everything went well you should see this yet great and uh we now move on to docker compose so run the following command to download the current stable release of docker compose so we'll copy that go in here firstly that's clear there we go that looks like that worked then we need to apply the executable permissions so go back in here there we have it and lastly we need a symbolic link you might not actually need this but i do this anyway it never fails or hasn't failed me there we go and that's it docker compose should be installed correctly so we use docker compose dash dash version it should come up with there you go so document version 1.2 9.2 obviously it depends when you're doing this that will be a different version that is us done so conclusion what have we done we've set up a virtual machine so we used a droplet on digitalocean as our virtual machine it's a ubuntu linux server so we set that up we've connected to it with a password first and foremost in visual studio code then we created some ssh key pairs added an ssh key to the authorized keys and connected via ssh and lastly we installed docker and docker compose that's me basically done so like i said at the start if you haven't already please subscribe and click that bell so you're notified every time i add a new video to the channel and also if you could drop me a like drop me a comment because uh it's massively helpful and also i like the feedback it helps me create content along the lines of what you actually want to see so thanks for watching i hope you've enjoyed it i've enjoyed making it and i hope it proves to be a very very useful video for you i'll be seeing you in the next video thank you [Music]
Info
Channel: Did Coding
Views: 10,279
Rating: undefined out of 5
Keywords: didcoding, digitalocean, ssh, tutorial, visualstudiocode
Id: dGBjBECs6m0
Channel Id: undefined
Length: 27min 14sec (1634 seconds)
Published: Thu Jan 06 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.