Docker-izing your Go Applications and Deploying them to DigitalOcean

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone is elephant tutorial age Donette and endless tutorial we're gonna be looking at how you can containerize your go applications using docker now docker is a truly excellent vet tech that allows you to specify the environment in which you want your application to live all within a simple docker fail now this effectively makes collaboration easier and Reza's of the works of my machine problem that is so prevalent and development teams across the globe so as such I felt like a great idea to write a tutorial and how you can effectively containerize your co-op locations using the docker container ization technology now by the end of this tutorial you should have a good handle on the following so you should be able to understand the basics of docker and how it's useful to us developers you should be able to write a simple docker file for your co-op locations and then finally we're gonna look at how we can deploy that's docker container and to add those to ocean droplet now if you want to follow this tutorial but don't have a dissolution account I'll be leaving a referral link and the description of this video and if you create an account with that referral link you'll get $100 in credit for the next 60 days so let's dive in no the first thing that I usually get asked as white Walker now I've been asked this a couple of times and to me the main benefit of docker becomes obvious when you're working on critical applications that require complex environment setup in order to run now essentially everything your application needs to run should be defined within a docker fail at the root of your application and that's will include things like environment variables and cool versions or bailed steps or instructions on what the data freeze need mounted and so on now by investing the time to declare these and a darker fill up front you essentially make your app portable across any machine that can run docker now if you have new developers joining a team you can simply point them to a repository with the docker file already defined in it definitely start commands to run it locally and that's them ready and set up to go and start contributing to your project now let's imagine we have an application and let's imagine that this runs using gold version 112 and it connects out to see a database now if a new developer comes in and joins a team and they'll typically have to set up and go version 112 in the machine they'll then have to retrieve the username and password for this database and then they'll have to find out how to build and run the application locally know the doc Rafael kind of minimizes that complexity note within the docker file we can specify things like from base image so we can see it from koulang and which is best by version 112 we could then see an environment variable say password because pineapple and we could then say okay bold and then run within a stalker fill now if everything is specified in our docker file we can then say docker bailed and we can build the image and then once we have the image we can then run it as a container on our local machine and we would then be running it with the exact same McMahons and our production environment let's dive into our editor of choice and create a nice and simple application that we can then containerize using docker and then deploy to digitalocean now I'm going to start off by creating a really nice and simple web server and it's gonna take an amine function and within this main function I'm gonna want to do the following so fmt doc don't mind go docker tutorial and I'm gonna set up a few routes so his TTP door handle funk and whatever someone hits this base route of my application I want to respond with this function so HTTP top response writer spawns later and a pointer to HTTP request and within this I want to do FM t dou F then F passing in a response rater and hello what old like so keeping it nice and simple and below that someone to do logged on fatal HTTP dot lesson and serve and we're gonna be running this on port 8080 one passing and L as the second parameter there unsafe I should import the three packages I've used and if we go ahead and try and run this locally we should see that everything works as expected so it kicks off my server and if I then try to open up localhost port 8081 I should see hello world printing it and my browser awesome so now that we've got really simple go out vacation up and running let's have a look at how we would add to talker to this particular application now the first thing we're going to want to do is within the root of our project directory we want to create a docker fail now before sign of s talker Phil is going to be the image that we want to base our own image off of now I'm going to specify a cool line and I'm gonna say one point twelve point zero - our pain is three point nine which are typically really nice and lightweight images and then after this I'm gonna start setting up this image so first thing we want to do is make the app directory in which all of our app code will live well then want to copy all of our project contents which is just min-koo for now and - that's newly created at the eight-three and will then want to specify he worked at a three slash up and then within that's worked directly we want to run the following command so go build and the output should be the mean expectable passing and the cutting today three no that should build up our binary executable and the next are the next and final stage is to check off that's binary executable and we can do that by passing in the command and seeing app slash mean like so save that little bit to find everything within the stock rafael we can then go ahead and create our image from it so I'm going to ctrl C my currently running server and I'm going to want to create a savage by using the docker bold command I'm gonna specify the name which will be my goal app and I'm going to specify its desperate today I want to build it from check that off and I'll run through all the set steps that we can already defined within our talker fail now just to verify everything is worked successfully I can then see all my images by taking docker images and if I can't to the top I should be able to see that the latest image is the micro app image and it was created two minutes ago cool so if I clear this and say I wanted to run the DES newly defining the docker image locally within a container I could do that by typing docker run I could see it interactive mode and then I could specify the port mapping so I'm going to keep it nice and simple and say 8080 maps to 80 81 and then I could specify the docker image that I want to run so my cool app and as you can see that's kicked off my application within a docker container and and interactive mode and if I could open up my browser and have localhost 8080 I should see that HelloWorld has successfully been returned awesome this container is currently running in interactive mode and it will live as long as this particular session lives so if I control see this I should see that my application has crashed now I can fix this by running my container and detach mode again specifying the port mapping and the image I want to run and that will kick off the container running in the background there in order to see all of the containers running on my machine I can do docker PS and let me let's waiter and as you can see the microwatt image is now you're currently running with a container ID of this and it shows the start command which is quite helpful when it was created and its status and again it shows the port mapping so that we can see that my local host port 8080 maps to the internal running localhost 8080 one within the container perfect now if I want to also kill that I can use the docker kill command I can then copy the container ID and that should kill that particular damage come back in here as you can see it's down perfect so I guess the final part of this tutorial is going to be deploying our newly containerized coop occation up to digitalocean now it let's run through the process that we're gonna be following so I've effectively got my application source files on my local machine now I'm going to effectively want to commit all of these fails up to a get repo I'm then gonna want to be able to create a droplet on digital ocean and from this droplet I'm gonna want to retrieve all my source files and then run through the door belt and the docker run commands just as we have done locally here no you would technically automate this process using a tool such as Jenkins or maybe even Travis CA but for now I'm just going to be showing you how to run through all of these steps manually just so that you got a feel for the process and you understand exactly what's going on know that first step to the process was to create a gap repository and push all of our source files up here now in the interest of time I've already done this and I've already pushed my source code that I've got here up to that particular repository now if I come into my desktop again and try and create new droplet select one click apps and docker and then specify be five dollars a month option to keep it nice and cheap and then click on my macbook or ayleid macbook SSH key which I've already set up on my local machine I then click create I should go off and start a server photos that I've already done this I'm going to come back into my droplets it's like the server I've just created from here I should be able to see things like the ipv4 address and things like the network bandwidth CP usage and des cailloux I want to copy that ipv4 address and within my terminal I went to SSH using the root account specifying the IP address and that should log me into that server cool so from that server I'll be able to do things like utilize the docker command which is already installed and it also comes installed with get already so the first thing I want to do is to tick that's cooling address here and get clone my source code into an app directory now you want some and that's app directory will see the app I'll then be able to do the following so docker build - T my goal app and this is the exact same docker Belgium and I ran previously and then I'll be able to check off a container using docker run detached mode and port 8081 to support 80 80 80 81 and my app and that should check off the docker container on my new server and I can verify this by you doing docker PS and I should see the container ID the image and that is created a second ago now if I come back and here copy that's ipv4 address paste up here and then append 8080 to the end of this address I should be able to see my newly deployed go application up and running awesome so and that's the tutorial we've been able to create a really simple cool application and we've then been able to continue eyes it using docker and creating a talker fail and then we've subsequently been able to deploy that application up to at digitalocean and server using both yet and the V talker command now as you can see I use the exact same docker belt and docker run commands as I did locally and again that's highlights the importance or the helpfulness of docker when it comes to running and applications across different machines OOP so that's all we're gonna be covering in this tutorial now just a quick reminder I'm going to believing that referral link and the description of this video for digitalocean and that should get you a hundred dollars worth of credit for 60 days so if you want to follow this tutorial and do yourself feel free to use that and if you enjoyed this tutorial for any helpful then please leave a like if you get any suggestions as to what I can do to make it better then please let me know in the comment section below and as always please subscribe to my channel for more programming content Cheers
Info
Channel: TutorialEdge
Views: 31,460
Rating: undefined out of 5
Keywords: programming, tutorials, coding tutorials, tutorialedge, go docker tutorial, go docker digitalocean tutorial, go docker droplet tutorial, go deployment tutorial, go docker deployment tutorial
Id: lIbdPrUpGz4
Channel Id: undefined
Length: 13min 36sec (816 seconds)
Published: Sun Mar 03 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.