Create a Python Dev Environment with Docker and VS Code | NetDevOps and PyATS part 1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
it's no surprise that i love network automation and python development this has been my journey for basically the last year and a half as it sits now and it's just been my new obsession but recently i was peer reviewing some content of another software developer at cvt nuggets trevor sullivan and he introduced to me the power of python development within containers on our windows system so what i want to do in this video is set up how that really works and then in the next video we'll actually talk about how we can use the pi ats container to build an isolated dev environment let's get going the first question we have to answer is why why do all of our development within containers rather than just locally on our own computer here's the thing sometimes it's challenging to get all of the packages stood up and installed and blah blah blah it's even kind of tricky to get python up and running within our own windows computer because you do have to do things like check that little box that says add it to the path and you do or you should at least change the installation directory to be accessible to all users rather than in your profile so when we use docker containers this is an isolated clean way that we can build our own little environment for instance maybe i want to build a flask api so what i can do is i can just pull down a docker container that has python in it i can launch into that container and install flask right there but then i pivot a little bit and i think you know what i'd also like to do some work on pi ats but that's a completely different project so what i can then use is i can use a separate python container and install pi atsm in that the cool thing about this is that vs code can attach to either one of these containers and do development within that environment and you can even save the files all the dev work that you do either in the container or locally on your own computer check it in the source control and do it all that way by the end of the time that you see this you'll probably realize like wow that is kind of cool that is really clean and at the end of the day to get this all up and running it's really not much more than just installing applications that's all you really have to do with the exception of one little part when it comes to windows subsystem for linux so let's jump on my screen and we'll go through the checklist of the apps that you install and what are in and configurations that you have to do along the way so here it is on the screen i've kind of brought up these tabs that you can see here and we're just going to write the checklist out on the screen the first thing that you have to get is docker itself and one of the cool things about the docker installation for windows is it will force you to install windows subsystem for linux 2. so check this out on the screen on docker.com when you click get started you'll want to download and run the docker desktop for windows check it out it's actually a little app now see this on the images it shows all the containers that i've pulled down and all the containers that i've deployed or i'm currently running it's a little cool little gui app that they've actually improved a lot upon i think so when you download this and you go through the installation here's what you need to know you're literally downloading and running an app so i'm just gonna write download run but then along the way it's gonna force you to do your first reboot i'm gonna call this reboot one so you'll reboot your computer and when you come up that's when it wants you to install wsl2 now wsl2 used to be baked into the docker installer but now it's actually going to pop up and say you must install this on your own and it actually gives you a little link to click on that takes you to the installer if you actually google wsl2 msi it's probably the very first one in the list here updating the wsl2 linux kernel give that a click and you'll see right here on the screen download the latest wsl2 linux kernel so in step one we've got download i'm gonna put docker here and then i'm gonna put like one a that's gonna be click on the link to take you to download and install the wsl2 linux kernel this is just a self-contained msi you can click next next next yes to everything and then you'll have windows subsystem for linux to install see the whole point of this is that you've got your computer here this is your windows 10 computer within it though it's going to be running a linux kernel this is called the windows subsystem for linux and all of the docker containers that you pull like python or maybe openva i'm running out of space openvas or maybe pi ats i'm running out of space again these are all going to be connected to this linux kernel they're all going to be running based on that now the really cool thing is is that you can fire up vs code and you can do your development locally on windows 10 or you can attach to each one of these little docker containers maybe one that already has python installed for you and you can do all your development there so at this point you will have downloaded docker you've gone through the installation process rebooted once it brings up a little after the reboot it brings up a little dialog box that says click this link to download wsl2 once you've downloaded and installed wsl2 within that dialog box there's a little button that says restart you click on that and it finishes the docker container installation for you and at that point you're close to up and running you see you've gotten docker and you've gotten the ability to run linux but you don't actually have linux yet that's the next thing is that you have to get a version of linux up and running within your windows subsystem for linux so all you have to do to do that is click on your little start button here and launch the microsoft store within the microsoft store you can search for ubuntu i don't know why it did this come on go full screen weird formatting on this screen today anyways you'll want to click on ubuntu 20.04 lts and on this screen you will see get you'll click that button first after you've clicked get you'll see a button pop up here that says install you'll click that and then after it's installed you'll see this button here called launch and guess what you want to do you want to click launch it launches a little terminal here and the first time you launch it it's going to ask you to set a root password that's what you have to do here set the root password you type a password in then you repeat the password and at that point you do have docker you do have the windows subsystem for linux installed and you do actually have a linux kernel up and running that's ubuntu 20.04 once you've typed in that password you are safe to close this down now there are a couple more things that i want to recommend that you install in order to actually get your dev environment up and running the next thing i'm going to say is git not github get this is get cli so if you go to git hyphen scm.com downloads you'll see it'll detect your operating system right here you can download it for windows or you can click here to download it for windows just accept the defaults for everything here look you don't have to have git in order to do all this stuff but git is like thanos it's inevitable if you're doing development at some point you'll want to work with git and this comes with a cli that makes working with docker really easy now as an alternative to get instead of working with source control you could download something cool like the windows terminal or heck you could download both the point is is that you can run docker commands from a power shell terminal the which runs within windows terminal or you can run them here within git the big difference though is that when you install git you get all of the functionality that comes with git and that comes with vs code as well now the last app that you want to install after you've installed git or windows terminal or if you've decided you're just going to go with powershell is of course vs code just go here and download and install vs code so let's recap here we we've done a lot we've got docker for windows installed which came with wsl2 we went through that manual installation process we got the get cli installed which was that get hyphen scm again that's a huge installer just accept all the defaults go through that and click finish and then you got vs code installed don't forget that after going through wsl2 you gotta launch the microsoft store and get ubuntu 20.04 and then set the root password by launching it after you've set the root password you are okay to close it you never have to open it again so again i know it seems like a lot but all we've really done until this point is just download and install apps that's it we just downloaded and installed things so if you can download and install apps you can do this stuff too so now that we've downloaded and installed apps what we need to do next is we actually need to get a python container so that vs code can do development in it check this out if we go to hub.docker.com this is where you can find all the containers of the world so if you search for something like python here it is right here here is a docker container this is basically an isolated linux environment that already has the latest version of python installed so you'll give that a click and you can see right here let me draw it right there those are the commands you need to run docker pull python so what i'm going to do is i'm going to click on start here and i'm going to go to my git bash again we got this so that we could actually type the docker commands as well as use the git commands if we wanted to so if i just click the copy button here and under get bash i'll paste it and press enter there it goes it's already pulled the latest version of python now while we're here we might as well set up what we're going to do next in the next video and that's get pi ats so let's do pi ats if you just search for pi ats on docker hub we're looking for cisco test automation slash pi ats so i'll copy this one here and we'll go ahead and pull that one down at the same time now when you run this because i've already pulled these it just pops right up and says it's done when you run it it's going to take some time to download and install these now here's the kicker these containers are not up and running yet all we've done is download them so if i say docker ps you see it shows no containers are currently running what we want to do is we want to start a python container that way vs code can attach to it and we can start doing python development there so the command to do that is docker run we're going to say hyphen d this is detached meaning that it's not going to take over this console that we're currently working with it's going to be running in the background basically if we didn't say detached right here this cli that we're in this git dash it would launch us into that docker container and that's not what we want to do next i'm going to say let's keep it interactive that way we could interact with it while it's running in the background let's give it a name something like python devs and now all we have to do is specify the container that we want to run of course it's called python that's what we said up above docker pull python that's what we're talking about now i am going to say bash so that way it launches me into the bash terminal of the container once it gets started up when i press enter here you see it spits out a little good thing here and that's how we know the containers up and running beyond that i can say docker ps and it shows me that there it is python devs right here under the name is up and running so now we're ready to launch vs code connect to python devs and start doing python development so i'm launching up vs code here and in order to connect to a docker container what we need to do is we need to install a quick extension these little blocks over here on the right hand side are where the extensions are search for the words remote and you'll see the first two remote wsl and remote containers go ahead and install both of those right now by clicking the red install button remote containers is what we really want to use but it's nice to have remote wsl when the time comes now on the opposite end of the screen down here in the bottom left corner that's how we connect to our remote container so give it a click and you see at the top of the screen we get this little window that pops up and we're going to say remote containers attached to a running container there it is there's python devs so when i give this a click it launches a new instance of vs code but look down here in the bottom now it shows us that we are connected to the container python devs and we can open a folder and we're actually exploring the actual linux kernel that's on that python container so if i click ok here i see that i'm now in the root container so check this out i'll go to file and new down here in the bottom right corner i'm going to change my language from plain text to python and i'll say print we'll say hello world and check this out i'm going to hit ctrl s to save and it asks me first of all do i want to save it right here in the root of our container which means this file will be saved within that specific container i'll click show local i can save it locally on my own computer that's the other option how cool is that so let me do this one more time i'm going to click file save as and i'll just click ok to save it here within my root folder now notice because vs code detected this was an isolated environment we have new extensions to install we have to install pylance we have to install auto pep8 again this is a completely isolated environment so i'll click yes to this i'll let it install pylint and i'll click yes to this as well and what it's doing is it's going through the installation process it's installing these functionalities in the container so it's totally contained beyond that you also see we've got a terminal that's been launched here in the bottom so all of the packages that i may want to install within just this container i can do that right here on the terminal like pip install blast now i have a flask container my python devs container is now my flask container and if i decide you know maybe i want to develop something else maybe i want to develop something for netcomp automation i can create a new docker container let me just change the name here to something like nc client dev now i have oh no docker ps now i have two containers running so here is my container where i've got flask installed if i jump back to my original vs code environment i can connect to another container in this case i'll choose my nc client live dev container and if i launch the terminal here i'll give it a pip install nc client do you see what i'm talking about here we have two separate python containers that now have two separate libraries and they're two separate development environments that i can work to my advantage and they do work see check this out i'll start debugging this right here i'll say it's a python file and it prints hello world so there we go now i have isolated dev environments and this is really really cool that i can just spin up python containers and install different libraries in them and i've got my own little environments for that i can still save these files locally which is super awesome because now i can check them into my local source control if i want to or i could just keep everything contained within this particular container so that's been setting up the first video about how we can set up a dev environment on windows with docker thanks for stopping by y'all i'll see in the next one when we're talking about pi ats
Info
Channel: Data Knox
Views: 9,255
Rating: undefined out of 5
Keywords: docker windows, docker, docker tutorial, vs code container, vs code docker python, docker python windows, vs code python docker, docker tutorial for beginners, network automation, network automation python, pyats container docker, pyats python, pyats framework cisco, pyats installation, pyats framework tutorial, pyats genie parsers, docker windows 10, docker container
Id: k8H0KCtsTR8
Channel Id: undefined
Length: 15min 35sec (935 seconds)
Published: Tue Oct 27 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.