Install Docker and Kubernetes on Windows Subsystem for Linux (WSL). No Docker Desktop Required!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys today I'm going to show you how to set up Docker on Windows now this is a fairly straightforward process but it's in lieu of Docker desktop now if you're using Docker desktop there's nothing wrong with Docker desktops it's a great piece of software it'll get you a great out of box experience that will have you up and running with Docker and kubernetes with the simple install of a piece of software however there might be a reason that you don't want to use Docker desktop and one of those reasons might be something like a more custom setup that you need on your particular environment another one might be licensing if you're working for an organization that has more than 250 people or more than 10 million dollars in Revenue they require that you get a license for Docker desktop whatever the reason might be you can easily install Docker using some of the common tools that are available on Windows so I'm going to show you how to use these common tools to get a Docker environment that'll work just like you had Docker desktop installed except you won't have the docker desktop GUI obviously but in all cases for all intents and purposes you'll be able to use it with your Dev tools you can use it on the Sim command line or whatever you might want want to do with Docker and whatever context that you might be working so to make all this work we're obviously going to need Windows 10 or 11 so a fairly modern version of Windows now because we're talking about mostly Linux specific Technologies we're going to need a Linux contacts so we're going to use wsl2 which is Windows subsystem for Linux on Windows and that's a fairly straightforward setup process that doesn't require any kind of virtual machine software like VMware or virtualbox you can install it natively from when within windows and then use the Microsoft store to get a specific distro now with wsl2 installed we can then install the two different environments so we're going to need a Docker environment and then a kubernetes environment so the docker environment of course is going to have the docker engine running so we'll install the docker engine in wsl2 and then we'll use chocolaty to install the command line which is the client software and then that will be set up and then we'll configure the two to talk together and then for kubernetes we're going to install kubernetes on wsl2 we're going to be using micro case for this which is a fairly easy to install kubernetes setup and you can just basically run one command and it just works and then we'll install the coupe cuddle which the client for kubernetes using chocolaty as well then we'll configure those two to work together and once you have all these components you're up and running with a full-fledged Docker environment that will let you do Docker development as well as kubernetes and development so installing wcl2 is pretty easy so open up your start menu and type in features and you'll see this option for turn on Windows features and that'll pop up this little dialog here so let me zoom in on that and you'll scroll down on this you'll see Windows substance over Linux right here so check that right there and that will give you Windows substitute for Linux and then you'll want to turn on virtual machine platforms so WSL is essentially a really lightweight VM that has tight integration with windows so it's not a full virtual machine experience you're not going to see a hypervisor and you're not going to feel like you're actually running a separate Machining because of the tight Integrations that it does have so it makes it feel much more native than a typical virtual machine so check those two and if you also want to enable containers for Windows containers you can check this option right here as well and once you have those checked then you click OK it will install the feature you may have to reboot your machine once those are done there's one other step that we have to do so the next thing we need to do is install the distro on top of wsl2 and that's pretty straightforward so open up the start menu then type in Microsoft store and you'll get the option for store right here and go ahead and launch the Microsoft store now this will take a second to launch but it's just going to download some content that you can see right here now once you have that you can then come up here to your search right here and type in Ubuntu and that will give you some options here so we're going to go with a bunch of 22.04 that's the LTS version and that's going to search for it and this is going to give you a lot of options here you can use for 22.4 20.04 and then this one right here but we're going to go with this if you have it installed already you'll see what I'm seeing here but otherwise you'll see an option for installer just click on install and then that will download and install WSL two's version of Ubuntu onto your machine and so that will install you might have to restart wsl2 if you've already done so but once that's installed your Linux context is ready to go and then we just need to open up WSL too and install the docker contacts as well as the kubernetes context so to start wsl2 it's pretty straightforward open up a terminal and just type in WSL and that will start up WSL too and the Ubuntu will boot it might take a first while the first time you have loaded it because it's actually loading the virtual machine in the background but once that loads then you'll get a prompt that looks like you're logged into a a Linux machine and so this will allow you to use this just like you were using a command shell inside of a Linux contact so I can run all the same commands I can then do everything like I can on a Linux context if I go CD TLD that'll take me to the root folder and you can see that I have a couple of things right here that are already installed so let's go ahead and install Docker inside of wsl2 which is actually pretty straightforward so let's go ahead and walk through these instructions so to finish wcell installation we need to enable systemd now systemd is just a service that manages other services it allows us to start and stop Services it controls the starting of services at boot and it will also handle things like crashing and logging and attempts to restart things and all of the things that a service manager will typically handle but it's not enabled by default on WSL so we're just going to enable it by simply adding a file to WSL and you do that by simply running Nano which is just an editor so we're going to run sudo Nano Etc wsl.conf and then type in a password for our WSL environment and then you add this text to the file if the file doesn't exist it'll create it and you just need to add this text right here which I'll put in the video description down below now once the file is edited you hit Ctrl o to save control X now drop out of WSL and then type in WSL dash dash shutdown and that will shut it down and then we type in WSL to restart and then that will restart WSL with that new configuration with systemd enable so to install Docker on wsl2 it's pretty straightforward we're just going to run a couple of commands inside of the prompt here so to do that we're just going to run it first a curl command to get a instance of get docker.sh which is just a script that will download and configure Docker in this context and I'll put these in the video description down below so you can run these commands so this will download get Docker and then we're going to do a chmod plus X get Docker like this and um what that will do is make this script executable and then we can run the script as such so we run around with pseudo and then we do Dash get Docker and that will then prompt us for the password and this will then allow you to execute this in the root context of wsl2 so it will sleep for a while uh give you a chance to abort and if you've already installed it then it will install it but if not just let this thing run through to completion it's just basically going to add some repositories to your apt packages and then it's going to use app install to install Docker on your machine so once you have this up and running you should be able to type in Docker commands idea Docker ps-a and this one is not running because I need to put sudo in front of it and that's because the docker socket right here is actually protected and we're going to expose that though whenever we actually configure this to use the docker client to talk to wsl2 now that we have Docker installed we're going to configure Docker with the system D startup and that systemd startup will just start Docker whenever we start WSL but we want to edit the start command so that it will be exposed to the Windows host for WSL so we're going to do that by editing the service for WSL which is just this Command right here so sudo Nano slash systemd system slash Docker dot service now in this file you'll see a line that has exact start it's got the path to Docker D which is the docker engine and then it's got Dash H and dash H is just a flag for Tel Docker where you want to expose this to and it's saying Dash host really and uh by default it's using just a Unix socket but we're going to add a TCP socket to the end of this so we're going to use Dash H and then we're going to TCP colon 0.0.0.0 colon 2375 which is the port number that this is going to be listening on so once we have that we hit Ctrl o and then hit Ctrl X to leave Nano and now we're going to reload the settings so we're going to do sudo and do system cuddle or systemctl and then we're going to do Damon Dash reload and that's going to reload the settings and then we're going to run sudo system cuddle and then we're going to restart Docker using this same thing so restart Docker and that will then restart Docker with that new host configured and it's now going to be running on 23.75 so to install the docker CLI we first need to get chocolatey on our machine you probably already have it but in case you don't there's a simple command you can run I'll put in the video description down below and it's basically just going to set some parameters in Powershell and then run a script from the chocolatey community that will install it so you'll need to be in a terminal under administrative mode for Powershell for this to work so you can do that just by going to terminal and then right clicking on that and then run as administrator but otherwise just run the script I've already run it so I don't need to reinstall this but once you've installed it exit out of Powershell and come back in and then you can type in choco and you should see some output that looks like this it'll tell you what version you're using and so on so we're going to use this to install the docker CLI and the coupe cuddles you know command line installing Docker CLI is super simple so we're just going to run choco install Docker and that will install the docker CLI and so if you already have installed you can click yes but I've already installed this so I don't need to install it so everything is up and running by virtue of that so if I just type in Docker right here I'm probably not going to get any I'm just going to be able to see the list of commands and so on I can't use it with the docker engine yet because I need to configure it to work with that Docker engine which is actually really straightforward as well now after installing the docker CLI we need to configure it to talk to the docker engine that we installed already now there's two ways to do this you can do it temporarily just using the command line or you can do it permanently and I'll show you how to do both so the first thing we need to do though regardless is get the IP address now this is pretty straightforward so to do this just run a command which again I'll put in the video description down below this is basically going to tell WSL to run this command inside of wsl's Linux contacts so it's saying give me the IP address and show it for the ethernet adapter zero so if I run this command it will give me some output that looks like this and so we're basically just looking for the IP address which in this case is 172.19.155.226 so you can copy that or you can just memorize it whatever you might want to do then you want to do a set for an environment variable since I'm using Powershell I'm going to use EnV colon and then I'm going to type in Docker underscore host and then I'm going to do equals and then we want to use single quotes and then type in TCP colon slash and then paste in that IP address and then put in the port 2375 that we configured when we set up the docker engine and with that we should be able to run some Docker commands against it so Docker ps-a not going to return anything but in any case you can see that it's reaching out to that Docker host and getting information from it and it can interact with it so you can build and build Docker images or pull documents whatever you're going to be doing with Docker so this means that our Docker environment is set up so this is temporarily setting the docker host so if we want to do this permanently we need to set it as an environment variable for either a user context or for every user in Windows so that's pretty easy to do as well so to set up environment variables type in uh open your start menu and type in environment up here in the search and you'll see an option under best match says edit environment variables right here on the control panel and then you'll see this button right here so the button is basically there to launch the dialog for setting environment variables so you can launch that and you'll see a dialog that will let you set them for either the user scope or for the System Scope now I've already set one on mine for the System Scope but basically what we're going to do is set a variable that looks like this so your set Docker underscore host and then you put in TCP colon slash the IP address for wsl2 then the port number 2375 the exact same data that we put in on the command prompt right here so once you have that click OK and you're done with that and you can click OK here and your environment variable is then set now you'll have to exit your terminal session and restart it but you can do that by launching a new Powershell session and then you can contribute to run Docker commands and everything should work fine if you want to check it just to make sure type in you can type in Dr EnV colon and that will show you all of your environment variables and you should see one for Docker host in there right there so again very easy to do if you've never done it it's this will make it permanent and so that you can edit that as you see fit and there's other ways to do it with Docker context and what have you but this is just for wsl2 for doing Dev work in this local environment in most cases apps if you're gonna be working in an IDE or something like that it's going to look for Docker host and the environment variable because that's where it's going to look for the docker contact so if you're using like eclipse or a visual studio code or Visual Studio that have Docker integration it's going to have this expectation that that's been set so once that's set everything should just work and you shouldn't have to do anything special to make all of those tools work with WSL too for your Docker environment at this point so now that we've set up Docker the next thing to do is set up kubernetes and kubernetes is pretty much the same kind of process we're going to use the command line to set up micro case and then we're going to use chocolatey to install our command line utility and then we'll configure the command line utility to talk to our kubernetes context so to set up kubernetes we're going to use snapcraft which is I wouldn't say it's a package manager but it's kind of like a package manager for installing what is called a snap now a snap is basically a program or a set of programs that is kind of bundled together that gets installed into its own isolated environment inside of Ubuntu or whatever Linux distributor that you might be using that's to support snapcraft now it's pretty straightforward to use it so we're going to be using it in the Linux wsl2 instance that we have installed so first we need to install it though and installing that is is easy to do so just run sudo apt-get install and you can just type in snap and that will ask you for a password and it'll install it I've already installed it so it's installed on my box and once you have snap installed then we can use snap to install microcates so once you've installed snapcraft it's easy to install the microcate snap so just run a single command snap install micro Kate's classic the classic parameter just tells it to use this in a classic way instead of using the isolated environment but otherwise it's going to feel like a Snap application so I'm going to run that I've already installed it so I don't have to reinstall it and by doing that it's basically going to start micro Kates as well and you can check on it by running micro case status weight ready and this will allow us to you probably want to run this as sudo and then it will tell you if it's running if things are working and so on and you'll see that everything is currently working in this context now there's some things that you can turn on and turn off now what we'll probably want to enable is ingress so if you don't have that installed so you can do micro case enable Ingress and that will enable Ingress controller on this guy which basically enables uh the ability to have HTTP Ingress which is pretty important for doing different kinds of things with our kubernetes context and the rest of this that it installs by default DNS and Helm are fairly well used uh so those are just installed by default there's a lot of other things that you can enable you can enable the dashboard if you want to use a GUI and there are some other things that you can enable like Prometheus if you want to get that logging and then storage uh if you want to use that but that's been deprecated and there's a lot of other things that you can able but all this to say is once you have it up and running it's pretty straightforward it's a full-fledged kubernetes environment but it's running on a single mode node so pretty much everything you can do in a kubernetes context you can do with micro case so there's no real limitations it's just you're running this in a single node setup so if you're going to be testing for multiple nodes and failovers and all that you need of course a multi node setup and and you can do that with microcates as well but for our purposes we're just basically going to use this one as it sits for our purposes of doing kubernetes development but with all that now we need to get the configuration for this and the configuration is basically the file that tells us what we need to connect to this and so that's just going to be using Cube cuddle and Kube cuddle will allow us to export that and then we can use that file and import it into our Coupe cuddle command line utility that we're going to install with choco so to get the configuration we need to run a utility to export it so micro case has that built right in so we can run a single file that will show us the configuration so you can just run uh sudo and we can do microcates config and with sudo and that will output a yaml file that has all of the data that we need to connect to this and like the host name for instance right there and then this is a certificate it uses for authentication and other parameters and then there's the token for the admin so all of this is in that yaml file but we need to put this out to a file or you can copy the text as well from the screen but we're going to just copy it from the screen because that's how we're going to import this into our local context in Windows so to do that I'm just going to highlight it all and then right click and that's going to copy it into the clipboard now I'm going to launch a text editor right here and I'm going to open up a brand new file and paste in my text right there and so you can see that it's just a pure text file so to save this we need to put this in a specific folder so let me zoom in on this real quick right here and um let's get this up a little bit closer so you can see what I'm doing and uh we're going to go into our C drive and then go down to users and then find your user and then there's a there's a hidden folder that you might not see I've got mine uh visible but um it's backslash if you just want to type it in Kube right here and this is the folder that contains your config files so if you do start on this folder you should be able to see all of the files that are in this and um I've got a few right here already uh where I've already imported this but any case what you want what you can do with this is save it off as a file name it doesn't matter what you call it it's just um a file name doesn't matter I can call it microcates one or something like that and just save it and that is going to save that text file and then we can use that to configure our kubernetes uh locally and that is after we install it using choco so installing a kubernetes CLI or Coupe cuddle is really easy to do once you have chocolatey installed which we already did you just run choco install kubernetes CLI now you'll need to run this as an administrator a Powershell administrator or you can run it as a command prompt using administrator mode but either way you run that and install it I've already installed this so I don't need to reinstall it but any case it's pretty straightforward and once you've installed it you probably have to close out Powershell and reopen it so that you get the path mapping but you should be able to type in could cuddle and with that you can then type in version or whatever commands you want to get it'll give you version information or you can just type in help and that'll give you help information whatever it'll give you lots of different uh options for running this now our concern is going to be inside of that coup folder where we saved that file that we got from microcate so if you CD to your user and mine is Blaze so CD Colon's c-con's users Blaze and then you dot Cube you should see a list of files now I saved mine as micro Cates one and if you already had a connection to an existing contacts for kubernetes you're going to see this config file right here and that is the default file so if you don't have one of these you can just simply rename this file as config and you're done if not what we want to do is we when we want to merge these so I'm going to show you how to do that so to merge those two files together first thing we need to do is set an environment variable so in Powershell we're going to do that with this we're going to set a a temporary variable right here you called kubeconfig and this will basically tell kubernetes which files to look at whenever it wants to configure so if you wanted to set a an environment variable like we did already for cool config and just have two separate files you can definitely do that and but what you have to do is you have to do a semicolon separated list of files so the default one of course is this one right here and then we're going to add to that that file that we just created so in this case SQL and user blaze.cube micro case1 and that will then set the environment variable for kubeconfig now with that what we can then do is then use Cube cuddle to flatten that so we're going to do cuddle config view dash dash flatten and then type in new config and new config is the output file name for our merged configuration and so if we do LS on this we should see a new file that says new config right there so if I do uh cat new config it will show you all of the different contacts that I have inside of my configuration right here so that is the merge version so once that's done I'm going to undo the config variable right here just to use config again like this and then I'm going to basically rename config to config.old like this and then I'm going to rename my new config to config like that and replace it and so now I have merged those two files together and I should have three files uh now config config.old and then of course micro case one so now that that's done I can now use kubernetes command line utility or scoop cuddle to connect to microcates so to list the contacts we're going to run Cube cuddle then we're going to type in config and then type in get Dash context and that will list all the contacts that are configured in that config file and then if I could spell context correctly it would give me the output and you can see that I have several of them listed already so I have um several that are online for whatever reason I've got a lot of different ones for that and then I have this one right here that I just imported and then this is when I was playing with and of course Rancher desktop if you're going to use Rancher desktop but in any case if you want to switch context that too is pretty easy all you need to do is um type in instead of get contacts you can say use context like this and then type in the name right here so in our case micro case and now I've switched context to microcates and I can then do Coupe cuddle commands against my micro case configuration so uh Coupe cuddle get pods for instance and that I don't have anything uh running currently but this is now configured to use our micro case configuration so now with all this let's test this all and see if it all works so let's run a Docker command against it to test our Docker install and then let's run one for kubernetes and we'll use that to test our kubernetes install so to test Docker I'm just going to run my dos game demo that I've used in other videos so I'm going to type in Docker run and then I'm going to do Dash p for a port forward and let's do port 8080 to Port 80 and then I'm going to tell it my command my container image that I want to run so it's going to be Blaze slash dos Dash game and that should run Commander Keen it's going to pull this and start running it as soon as this pull is done we'll be ready to go okay it looks like everything is up and running so I should be able to use the Dos command to connect to this guy so that is going to be on port 8080 on the IP address for my uh instance of WSL so let's go ahead and connect to this using a browser so I'm going to type in HTTP colon and then we'll put in the IP address or WSL and then port 8080 and that's going to pull up a list of files here I'm going to click on VNC connect this guy type in password one and then that's going to give me my dos box instance running inside of a container right here so I should be able to just type install and that's going to install Commander Keen and once this is installed I can make the game playable and I can run this and this will allow me to play Commander Keen inside of a container running on wsl2 using the uh what we just installed on top of that so again fairly easy to do nothing really to it so here we go and we're just running this and playing Commander Keem so that's that let's go ahead and use the same thing to run another instance of this game but this time in kubernetes so to test kubernetes I'm just going to run a simple kubernetes manifest file so I run cat on keen.yaml you can see that it's just deploying a deployment a single node a single pod deployment right here Exposed on Port 80 and then it's using a service on a node port to expose it so I'm going to be reaching out to port 31000 on the IP address of the wsl2 instance that we got earlier so to deploy this cuddle apply Dash f iend.yaml and everything is created and I can do get pause to show you the pods that are running I can do get services for services and of course deployments um for deployments and looks like everything is already up and running so if I launch a new window and I go to http colon slash 172 there it is um I'm on Port 31000 on the IP address of wsl2 so I'm going to click on this and this is going to pull up node VNC and I'm going to type in the password for this it's password one really secure I tell you and um I'm going to zoom out just a bit here so we can get the whole thing on the screen and I'm going to install this and that's going to install Commander keen and then we can launch it of course and play our game in a browser uh this time running on kubernetes so all of this is pretty straightforward I know there's a lot of command line utilities that you have to run and so on but it's actually a fairly straightforward process it's not as easy as of course installing something like Docker desktop but all things considered it's probably in my opinion the most straightforward way to get a Docker environment up and running with a little or no fuss using a lot of the tools that are very familiar like chocolaty and on using wsl2 and using different things available on the Ubuntu command line like at get or snap and so all of these things work together give you a full-fledged Docker environment that you can use for Docker development so Building images and so on and for doing kubernetes development as well so building kubernetes is Manifest building Helm charts doing all that kind of stuff and testing and deploying those things as well so again it's something that I've used in the past and this is actually my preferred way to do this but if you want to use Docker desktop certainly use the tool that you can use ranch or desktop as an alternative but I prefer this kind of more manual approach because it gives you a lot more finesse and of course it gives you a little bit closer to the environment so that you get a little bit more familiar with how all these tools kind of work together so again something to check out if you like this content please subscribe to the channel and like this video share with your friends and let me know what you think in the comment sections down below if you have other tips and tricks for installing this kind of stuff I'll be glad to follow up on you with you on any questions you may have or if you have a more efficient way certainly tell me all about it I'd love to hear about it so thanks for watching and as always looking forward to seeing you on future videos if you like this content please consider subscribing the channel by clicking on the Subscribe button you can also like this content by clicking on the thumbs up or share this content with your friends and also comment in the comment section down below you can also find me online at www.blaze.net or on Twitter at the one mule and as always thanks for watching [Music]
Info
Channel: Tech on Fire
Views: 4,122
Rating: undefined out of 5
Keywords:
Id: D46VybHqe0M
Channel Id: undefined
Length: 32min 36sec (1956 seconds)
Published: Thu Sep 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.