Windows WSL 2 Docker Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back guys today we're going to learn how to correctly run Docker on Windows 11. to run Docker on Windows there is few ways you can either run it using the docker Legacy hyper-v backend or you could use wsl2 which offers a much better performance and stability when using it on Windows the Windows system for Linux WSL lets you run a Linux environment directly on Windows without needing to use Virtual machines or dual boot setup this allows you to fully take advantage of running Linux directly on your Windows machine it's faster it consumes less resources than running a virtual machine it's integrated which means that you can directly access all your files on your Windows machine if you're planning to run Docker on Windows then it's highly recommended that you use wsl2 for your Docker desktop backend as you can leverage Linux workspaces and avoid having to maintain both a Linux and windows build Scripts to install WSL we're going to go to Google and in here you'll want to search for Microsoft WSL it should be the first result under the domain learn.microsoft.com and in here you should have all the instructions to install WSL for the most part you're going to open your Powershell and you'll want to execute this statement for the Powershell you have to open it as an administrator so let's go ahead and search for Powershell and let's run as administrator now in here you want to run WSL install I already have WSL installed for me locally for the most part once this command finishes executing you'll want to restart your computer when you're done restarting your computer you will see this prompt in here you will want to enter your username for your Ubuntu default wsl2 instance I'm gonna call mine emad now let's go ahead and set our password and that should be it for the installation part before we dive further it's important that you create a WSL config file the WSL config file allows you to configure all your Linux distributions running in wsl2 you can use it to do things like limit the memory and processors for your WSL distributions to create a WSL config file we're going to go to our C drive users and you want to go to your main users folder and here you want to create a new file let's go ahead and open notepad and I'm going to copy this location and let's go ahead and save a new file inside our main user directory for the type you're going to select all files and for the name you want to add dot WSL config in here you'll want to add square brackets and you want to write WSL to under here we're going to set our options for memory you want to make sure you select a reasonable number depending on how much RAM you have you don't want WSL to match max out all your RAM in making your computer not usable the other option is processors and for this one you can limit how many processors you want your WSL to use you can say for for example two for me I'm gonna leave it out let's go ahead and save this file and you want to make sure it's inside your main user directory folder now at any moment you want to access your default WSL distribution inside your file explorer you want to go ahead and add two backslashes and write WSL in a dollar sign and here you can see this is our distribution Ubuntu you can click on it and here you're able to browse your Linux instance also inside your file explorer if you scroll down you should be able to see this section here it's brand new once you install WSL if you collapse it you should see your distribution in here obviously if you have more than one distribution you will see them under here let's go ahead and open our Command Prompt in here let's go ahead and see what's the status of our WSL distributions so I'm going to write WSL two dashes and list in here you should see we only have one Ubuntu distribution and it is set to the default now if you write WSL list again and then here write variables you should see the status of your WSL instance so mine is stopped if you want to start your instance there's multiple things you can do inside the command prompt you can write WSL tilde and now you can see here that we are logged in as our user emad so if you're a ls-la you should see your Linux directory files let's go ahead and write exit to exit our instance another way to start your WSL distribution is by clicking on it in here once you open this folder it will automatically start another way to connect to your instance is you can now go to your windows and you want to search for Ubuntu and you should find this installed Ubuntu on Windows if you open this it will open the terminal to your WSL instance so let's do ls-la and you can see we are inside our WSL Ubuntu instance now let's go ahead and exit this and let's go ahead and open our Command Prompt in here you want to write WSL two dashes list and do the verbose option again so you can see our instance is stopped I'm going to open ru12 Terminal so I have it open right here and let's go ahead and write WSL list verbose and you should see we have a running status now to shut this down from the terminal you can write WSL to dashes shutdown and you if you see here on the bottom my terminal was closed automatically let's go ahead and write WSL list verbose and you should see our instance has stopped if you have Docker installed you can go ahead and skip this step let's go ahead and go to docker.com in here just go ahead and click download Docker desktop once that's done go ahead and run this and install Docker once the installer is done you will have to restart your computer once you restart your computer you should see this screen pop up you want to go ahead and accept and we should be able to see that Docker is working so right now Docker desktop is starting and let's go ahead and skip the tutorial and we have Docker working for this step we want to make sure that our Docker is using WSL and we turn on Docker compose version 2. in the user interface you want to go ahead and click on settings on the top right in here you want to make sure that you have this flag enabled use the WSL tool based engine scroll down all the way and you want to go ahead and select use Docker compose V2 and click apply and restart this is an optional step but I highly recommend that you guys install the WSL extension for vs code the WSL extension will let you use vs code in WSL as you just would when you use your windows inside Visual Studio code you want to go to extensions in here search for WSL and you should find the first result by Microsoft open this and you want to go ahead and install this extension once you have the WSL extension for vs code installed you can go ahead and click on Terminal on the top click new terminal in here you should be able to see that you have this Ubuntu WSL terminal click here and this should take you inside your default Linux distribution for us at 2.2 now inside this terminal let's go ahead and write CD tilde so this will take us to our home directory let's do ls-la and you should see that we are inside our Linux now we're going to learn how to use Docker with wso for this you're gonna need to download a project if you have any projects available you can use those if you don't you want to go to google.com search for GitHub emad zamut z-a-a-m-o-u-t this is my GitHub account it should be the first link in here and in here you want to go to repositories and there's multiple projects you can pull let's go ahead and pull the laravel complete dockerization project copy the URL now we're going to go to our terminal in here click Start and search for Ubuntu and you want to open the Ubuntu terminal and here let's go ahead and see what's inside our main directory all right now in here I'm going to create a new folder let's call it workspace and let's go ahead and go inside our folder and in here let's go ahead and create another folder for our project and I'm going to call it laravel Docker example let's go inside that project and let's do get pull and you want to paste this URL here before we can pull our repository we have to run get a net first now let's go ahead and pull our project let's go ahead and do LS LA and you can see we have all our files on here now to open vs code there's multiple ways to do this I'm going to start with the easiest way go ahead and open vs code you could go here open folder and on the top here you want to search for two backslashes WSL and a dollar sign and here you want to select your Ubuntu and in here you want to go to home your user and you can see our folder in here workspace and you can open this in here now when you do when you launch this the first time you will see this prompt and let's go ahead and Trust all authors now when you open it this way you will see this notification in here and this will tell you that you should open this project in WSL and it will give you the option to do that here so you can click here and it will relaunch visual code and you can see here this label WSL you want to so right now we are directly inside our vs code now let's go ahead and close our vs code now another way to launch your projects inside WSL in vs code you can go to your terminal so let's find Ubuntu and then here let's go to our projects folder so I'm going to do Ls I'm going to go inside workspace I'm gonna go inside my project folder and now you can run code Dot and this will open visual code in the current directory and if you do it from WSL it will open it directly using WSL this is how I recommend you should always open your projects now let's test if Docker is working let's go ahead and click on the terminal here let's click new terminal and now let's do ls-la in here make sure we are inside our projects and let's clear this now what I'm gonna do is I'm going to write Docker compose PS let's see what's the status now when you get this error when you try to run any Docker command inside your Linux distribution the command Docker could not be found in this wsl2 distro what you want to do is you want to open your Docker interface and here you you want to go to settings and go to resources the last option WSL integration in here if you see there is a checkbox for Ubuntu you want to go ahead and check this click apply and restart and once this is done let's go ahead and go back to our terminal and write Docker PS and you can see now Docker is working let's go ahead and run our sample project so I'm going to write Docker compose up Dash D now looks like I got this notification here you will have to allow Docker in your firewall and let's go ahead and run our Docker compose up Dash D flag again if you get this error which you shouldn't be getting this error you'll just need to rename this file Docker here to lowercase Docker you shouldn't be getting this error because this is something that I fixed in my Branch all right now here you see that we're getting permission denied error inside this file you should be seeing this error now this is very common when you're pulling projects from GitHub for the first time obviously those will not have the correct permissions set let's do ls-la and let's take a look at our permissions in here let's go ahead and go inside our Docker folder so we're gonna do CD Docker let's do a list LA here and you can see this file it lacks permission to fix this you want to write chmod plus X and the file that you want to Grant permission to and it's going to be our entrypoint.sh now let's go back to our project main directory and let's run Docker compose up Dash D again and looks like it's working let's check our container's status so I'm going to write Docker compose PS now it looks like we have some errors when we're trying to build some of our containers let's go ahead and open Docker and here you should see your project let's just check out the logs quickly I'm gonna go to my PHP container and in here it looks like we're having some more permission errors let's go ahead and go to our terminal and here let's go ahead and do ls-la and if you take a look here our vendor folder and our node modules folder these are being created as the root user this is very common problems that you will have when you use Docker on WSL so to fix this we're going to write shown so c-h-o-w-n you want to write your username in my case it's emad colon emad and we want to set our user for the vendor folder if you get this error you just want to do it with sudo and you want to do the same thing for the node modules folder and let's do a list LA to confirm and you should see that our vendor folder user is changed from root to our current instance user let's go ahead and write docker compose up Dash D and once that's done let's give this a try let's go to our browser let's go to 127.0.0.1 at Port 8000 and you should be able to see this laravel project let's go ahead and give it a try let's send a message and you can see this is using websockets so it's basically a live chat application let's connect another user and let's send a message let's say hi now let's go to the other page and you can see without refreshing the page that we have our messages in here thank you for watching guys if you found this tutorial useful click on the like button if you guys have any questions feel free to post it on a comment down below and we'll see you on the next video
Info
Channel: Emad Zaamout
Views: 5,855
Rating: undefined out of 5
Keywords:
Id: kaQQVoEBumY
Channel Id: undefined
Length: 14min 40sec (880 seconds)
Published: Sun Oct 23 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.