Docker-izing your Go Applications and Deploying them to DigitalOcean

  Рет қаралды 42,083

TutorialEdge

TutorialEdge

5 жыл бұрын

👨‍💻 For the price of a ☕ every month, sign up and gain access to a growing list of premium courses on my site - tutorialedge.net/pricing/ 👩‍💻
● SUBSCRIBE to see more of my Videos & hit that LIKE button to support the channel!
Referral Link : m.do.co/c/b348c7113c88
Running Demo: 159.203.190.213:8080/
Docker is a truly excellent bit of tech that allows us to specify the environment in which we want all of our applications to live within a simple `Dockerfile`. This effectively allows for easier collaboration and rids us of the "it works on my machine" problem that is soo prevalent in development teams across the globe.
As such, I felt it would be a great idea to write a tutorial on how you can effectively containerize your Go applications using the Docker containerization technology.
By the end of this tutorial, you should have a good handle on the following:
- The basics of Docker and how it is useful to us developers
- Writing a Simple Dockerfile for your Go applications
- Finally, we'll look at how you can deploy these applications easily to DigitalOcean
Why DigitalOcean? we'll I'm secretly hoping they start sponsoring some of my upcoming video tutorials so that I can start focusing on writing content full time! :D
Buy Me a Coffee: www.buymeacoffee.com/tutorial...
Patreon: / tutorialedge
‎● My Twitter ► ⁦‪ / elliot_f
‎● My Website ► tutorialedge.net

Пікірлер: 54
@ashafloki
@ashafloki Жыл бұрын
Finally a decent and simple tutorial that does only the basic but does it very well
@inversemetric
@inversemetric 4 жыл бұрын
Thanks for valuing my time! I'm not even a Go developer but I got enough value from this to solve my problem.
@David-mw5sd
@David-mw5sd 4 жыл бұрын
By far the best docker tutorial overall. Many don't cover how to make it run on a server.
@FernandoJimenez-cd1ui
@FernandoJimenez-cd1ui 5 жыл бұрын
You can push the image to a private repository and then, in your droplet pull it, thank you for the video, it helped me a lot
@mohammedammarkurabi7520
@mohammedammarkurabi7520 5 жыл бұрын
Excellent tutorial, Thank you
@oneware387
@oneware387 5 жыл бұрын
Clean video! Straight and to the point
@albinsjolin649
@albinsjolin649 4 жыл бұрын
Thanks dude, you really know your stuff
@antonnekrasov5670
@antonnekrasov5670 5 жыл бұрын
Great stuff man
@bikhoda6508
@bikhoda6508 4 жыл бұрын
Great tutorial. No-nonsense basics par excellence. Please make one about go modules.
@davidjiang7929
@davidjiang7929 3 жыл бұрын
that was a good tutorial! thank you
@themichael8767
@themichael8767 Жыл бұрын
Thank You very much, Sir 🤍
@zhandosyernazarov3086
@zhandosyernazarov3086 Жыл бұрын
This is good one, what I needed
@khazartalibov7911
@khazartalibov7911 2 жыл бұрын
Great tutorial !
@letsgoooo361
@letsgoooo361 4 жыл бұрын
thank you so much
@ivanstrelka3448
@ivanstrelka3448 2 жыл бұрын
thx so much
@AphixDev
@AphixDev 3 жыл бұрын
This is like a combination of all 10 hours of tutorial I wasted my time on in the last 3 days, all condensed into little more than 10 minutes
@ThatGuyAnonymous
@ThatGuyAnonymous 4 жыл бұрын
Good stuff
@datdang2492
@datdang2492 3 жыл бұрын
Thankss
@nicolasparada
@nicolasparada 5 жыл бұрын
Good tutorial 👍
@Tutorialedge
@Tutorialedge 5 жыл бұрын
Glad you liked it! :D
@marcuscavalcante5515
@marcuscavalcante5515 4 жыл бұрын
which is your vscode theme? Great tutorial, thanks a lot
@Isookov
@Isookov 5 жыл бұрын
Great stuff man, keep up! Can you please make one on Go with GrapQL with authentication/authorization? Would be AWESOME to see that!
@ravindranathmopparthy8116
@ravindranathmopparthy8116 Жыл бұрын
You could add multi-staged docker build to reduce the image size drastically.
@Oswee
@Oswee 5 жыл бұрын
As you said in beginning - "dockerization" is great for complex deployments. Based on that statement i would like to see more complex scenario. Let's say we have an monorepo with `/cmd/srv1/main.go`; `/cmd/srv2/main.go` and related `/internal/srvN/*` directories. Basically we have 2 separate services. Ignition main.go are in separate directory and all it does just calls some server from `/internal/srvN/*` or it could be even `/pkg/srvN/*` directory. (Some persons use `internal` for app and `pkg` for reusable packages). go.mod and go.sum of course sits at the root of the project. There could be `/build/*` directory as well which holds all the build scripts and Dockerfiles as well. I think - this is most common layout for non-sandbox projects and so... i would like to see Dockerization workflow in close to real-world environment. Ouh... and multistage scratch build - `FROM golang:1.12-alpine as builder ..... FROM scratch ....` to get as slim as possible container.
@Tutorialedge
@Tutorialedge 5 жыл бұрын
Hey Dzintars, thanks for your suggestions! I'll add this to the backlog! For an example of multistage builds, I have created a text tutorial which can be found here - tutorialedge.net/golang/go-multi-stage-docker-tutorial/ I just haven't had a chance to record the video yet!
@Blixzful
@Blixzful 5 жыл бұрын
Thank you! How would you add dependencies to the container?
@nicolasparada
@nicolasparada 5 жыл бұрын
You can use go mod and run the command at the dockerfile: RUN go mod download
@needlessoptions
@needlessoptions 5 жыл бұрын
@@nicolasparada Note that the Alpine images don't have git, so you need to build your app on a separate golang image with a multi-step Dockerfile, and then copy the executable to an Alphine image that you can run the service on. I just had to do this myself lol
@nicolasparada
@nicolasparada 5 жыл бұрын
@@needlessoptions Yes, a multistage dockerfile using the golang image is the way to go.
@syed_sha_saqlain
@syed_sha_saqlain 4 жыл бұрын
how does multiple containers communicate when deployed using docker-compose file?
@a-a-ron13
@a-a-ron13 3 жыл бұрын
Great tutorial! One suggestion that I recommend for all your videos that create resources that potentially cost money: at the end of the tutorial video, show how to clean up all the resources that you've created so that newcomers don't accidentally get charged after the first 2 months (or even sooner).
@vincentyoumans
@vincentyoumans 4 жыл бұрын
Three questions. 1... How could I use a Private Git Repo 2... How could I Branches of Git 3... How could I use continuous integration to submit my gocode, and have it automagically recompile and redeply Extra Credit... 4... How about compiling to a scratch container? Great Tutorials...
@Tutorialedge
@Tutorialedge 4 жыл бұрын
Sure! 1 - So, the docker command line tool allows you to login to private repositories should you wish. I chose to do the git -> docker build -> docker run method here as it removes DockerHub as a dependency for the video. 2 - If you wanted to build off a 'test' branch for example, after the git clone stage, you would git checkout TEST_BRANCH_NAME and then proceed to build and run the container as demonstrated in the video. - - You also have the option of tagging different versions in a docker repo, so if you use a private repo, you could build your image and push it using a 'test' tag and then run that 'test' tag on the droplet. 3 - This is slightly harder to do, effectively you will have to set up a CI tool such as travis to watch for code commits to your repository. You could then create a script with the Doctl and programmatically deploy a new droplet with a 'userdata' script that performs the `git clone... docker run` tasks. This is a great idea for a tutorial though so thank you! :D 4 - Multi-stage containers - tutorialedge.net/golang/go-multi-stage-docker-tutorial/ Hope this helps!
@fresonn
@fresonn 5 жыл бұрын
What font in your vs code?
@joshuasmith2814
@joshuasmith2814 2 жыл бұрын
Nice video! Wouldn't it be easier to just put and pull the docker image from git?
@thanusan
@thanusan 3 жыл бұрын
I'm a bit confused here, do I need Gunicorn to deploy my app? I can't seem to access my app via public internet once the docker container is running on my server
@oussamasethoum1665
@oussamasethoum1665 2 жыл бұрын
what's the theme you use for your vscode ?
@KrishnaDasPC
@KrishnaDasPC 5 жыл бұрын
How can we add MySql to this?
@joshuam6013
@joshuam6013 4 жыл бұрын
Can you add this container to a kubernetes cluster ?
@Tutorialedge
@Tutorialedge 4 жыл бұрын
You can indeed! I've done a video on just this subject here - kzfaq.info/get/bejne/ncVdiJibycq3pYE.html I hope this helps! :)
@AndrewElegante
@AndrewElegante 4 жыл бұрын
I had an issue with trying to connect to the webapp when running in the docker container on my windows 10 machine. localhost:8080 didn't work and, after visiting stack overflow, I found out that I had to run docker-machine ip to get the actual address to use. typing this 192.168.99.100/:8080 Hello'd my World and got me back on track. Might want to give people a heads up and/or explain how to avoid that error Everything else was perfect. Thank you for the great starter tutorial!
@Matthew-tl2ng
@Matthew-tl2ng 4 жыл бұрын
Why. Why have I been trying to figure this out for hours....HOURS. And a freaking youtube comment that I accidentally read actually made me not think im doing everything wrong but I have the dam url wrong. You sir have said me probably hours of more time and exhaustion. Thank you
@serioussounds2507
@serioussounds2507 3 жыл бұрын
Mate whereabouts in glesga are you fae
@fajara.r1379
@fajara.r1379 4 жыл бұрын
and how to use gitlab ci deploy docker go app on server ?
@rafaelcarvalho2918
@rafaelcarvalho2918 2 жыл бұрын
Qual é esse tema para o vscode - what's this theme in vscode
@miluna94
@miluna94 5 жыл бұрын
Wouldn't it be better to upload the image to a Docker Registry and download the image and run it from the droplet instead of downloading the git project and building the image again?
@Tutorialedge
@Tutorialedge 5 жыл бұрын
You certainly could, I actually wasn't aware DockerHub allowed you to create private repositories now! So if you were concerned about privacy then you could certainly use a private repository on DockerHub or you could use private repositories and do the way I did it within this tutorial.
@nulblaze
@nulblaze 5 жыл бұрын
Yup! This is what I did instead, great video though! :)
@PhanorColl
@PhanorColl 5 жыл бұрын
why did you use ADD instead of COPY?
@Tutorialedge
@Tutorialedge 5 жыл бұрын
Hi Phanor, both achieve very similar results with very minor differences between the two commands. ADD actually allows you to specify URLs as a source and map that to a destination within your container, however if you end up using ADD with a .tar.gz file, you'll find it automatically gets unpacked for you which may not be what you want. For more in-depth information, you can check out the Add documentation: docs.docker.com/engine/reference/builder/#add and the COPY documentation: docs.docker.com/engine/reference/builder/#copy
@theVoidyTv
@theVoidyTv 5 жыл бұрын
This is not how anyone should deploy anything besides test apps. Nice video man, but this is so wrong if someone would use it for prod that would be a disaster.
@Tutorialedge
@Tutorialedge 5 жыл бұрын
Absolutely, this video should not be used as a reference for getting things into production. There is one thing I'd like to highlight which is that nobody should ever run a single instance of anything in production unless you can tolerate significant periods of downtime. This video shows how to deploy a single instance of an app, but if you want to factor in resiliency then you ideally need to provision a load balancer which balances any incoming requests over multiple docker containers running on separate hardware and ideally in separate data centers. Thanks for your comment! :) I am planning on doing a follow-up video on that fairly soon, but if you have any other concerns/opinions that could make that video better I'd be delighted to hear them before I record!
@theVoidyTv
@theVoidyTv 5 жыл бұрын
@@Tutorialedge maybe adding multistage build to the docker is better so you deploy to pure alpine. So * Multi stage * Register running * Deploying images via register * K8 ? but that is a lot of tutorials or something so might take some time. Also you can make a setup for development and show how to manage development and production setup for Go+Docker+Maybe K8.
@amirhosseinahmadi3706
@amirhosseinahmadi3706 2 жыл бұрын
I know this is an old comment but if you see this by any chance could you elaborate a bit on exactly which part of this process is so wrong? I'm a bit confused. Thanks.
Go WebSocket Tutorial with the gorilla/websocket Package
13:46
TutorialEdge
Рет қаралды 63 М.
Understanding Contexts in Go in 5(-ish?) Minutes
15:14
TutorialEdge
Рет қаралды 60 М.
Gym belt !! 😂😂  @kauermtt
00:10
Tibo InShape
Рет қаралды 17 МЛН
Эффект Карбонаро и нестандартная коробка
01:00
История одного вокалиста
Рет қаралды 10 МЛН
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 37 МЛН
How I deploy serverless containers for free
6:33
Beyond Fireship
Рет қаралды 472 М.
ЗАПУСКАЕМ Golang ПРИЛОЖЕНИЕ В ДОКЕРЕ
16:32
The Art of Development
Рет қаралды 10 М.
Go + Microservices = Go Kit [I] - Peter Bourgon, Go Kit
38:49
CNCF [Cloud Native Computing Foundation]
Рет қаралды 102 М.
Working with JSON in Go - Tutorial
14:14
TutorialEdge
Рет қаралды 42 М.
Gym belt !! 😂😂  @kauermtt
00:10
Tibo InShape
Рет қаралды 17 МЛН