Spin up an Nginx Docker Container as a Load Balancer

  Рет қаралды 38,916

Hussein Nasser

Hussein Nasser

4 жыл бұрын

In this video we explain how to spin up a docker container that is running nginx load balancer. We will use an nginx.conf file to configure and load balance two services right from our container. We will then build a dockerfile inherit from the base nginx docker image and overwrite the default nginx.conf with ours.
Configuration
github.com/hnasr/javascript_p...
Cards
0:40 Nginx Crash Course
1:30 Node Js Docker lightweight
Timecode
nginx.conf 2:44
Dockerfile 4:44
🏭 Software Architecture Videos
• Software Architecture
💾 Database Engineering Videos
• Database Engineering
🛰 Network Engineering Videos
• Network Engineering
🏰 Load Balancing and Proxies Videos
• Proxies
🐘 Postgres Videos
• PostgresSQL
🚢Docker
• Docker
🧮 Programming Pattern Videos
• Programming Patterns
🛡 Web Security Videos
• Web Security
🦠 HTTP Videos
• HTTP
🐍 Python Videos
• Python by Example
🔆 Javascript Videos
• Javascript by Example
👾Discord Server / discord
Support me on PayPal
bit.ly/33ENps4
Become a Patreon
/ hnasr
Stay Awesome,
Hussein

Пікірлер: 56
@hnasr
@hnasr 2 жыл бұрын
If you enjoyed this, check out my Introduction to NGINX on udemy grab a discount coupon here www.husseinnasser.com/courses
@jamaScript
@jamaScript 2 жыл бұрын
I just got it, and enjoying it so far
@MARK01986
@MARK01986 3 жыл бұрын
Thanks a lot, man.!!! Greetings from Mexico
@nithinstrack-shiningsun5556
@nithinstrack-shiningsun5556 4 жыл бұрын
Thanks for sharing!!!! Great learning
@blossomkalabaw7941
@blossomkalabaw7941 2 жыл бұрын
thanks that was great. Quick and Concise
@ricardohincapie1537
@ricardohincapie1537 3 жыл бұрын
Thanks for sharing. Appreciate it.
@DennisHosangJr
@DennisHosangJr 4 ай бұрын
I appreciate the great video. Thank You for putting it together
@LuisMorales-oc5sz
@LuisMorales-oc5sz 4 жыл бұрын
Excelente video !
@mikedoouglas
@mikedoouglas 3 жыл бұрын
Great video!
@ambarmanu
@ambarmanu 3 жыл бұрын
My proxy server does not run and it gives in 502 error. Followed the same step by step as shown in the video
@jsphkhan1
@jsphkhan1 4 жыл бұрын
Hussein...Eid Mubarak. Thank you for sharing this video. I was getting 502 Bad Gateway initially when I tried to use localhost (for my node instances) inside my docker image. Replaced localhost with IP, and it working now.
@hnasr
@hnasr 4 жыл бұрын
Joseph Khan Thank you for Eid wishes ❤️ Eid Mubark to you too if you celebrate Yeah using localhost in the docker can be confusing. The best thing is to use ip address or host name Check out this video where i show how to spin up multiple microservices in docker kzfaq.info/get/bejne/b9lxmpqD1NWpdJc.html
@shahinbayat
@shahinbayat 4 жыл бұрын
Thanks dude. Traefik is also grabbing attentions and seems to work very well with containers, the API GUI is also interesting🙂 . I think it is also able to solve the problem of lacking load balancers in docker Swarm. Would be great if you could have an introductory video on it. Many thanks as always for your nice vids.
@hnasr
@hnasr 4 жыл бұрын
Shahin Bayat thanks Shahin! Ill take a look at Traefik good idea!
@mayurchavhan8590
@mayurchavhan8590 4 жыл бұрын
This is great tutorial Hussein, Thank you for sharing... Can you do a Traefik proxy using docker that'd be great.
@dnldnl4880
@dnldnl4880 2 жыл бұрын
Great video nice simple
@hicalls
@hicalls 3 жыл бұрын
many thank brooo. you saved my paper !!
@doghosuedean
@doghosuedean 4 жыл бұрын
"I'm going to use vim" good lad, hitting subscribe
@hnasr
@hnasr 4 жыл бұрын
Dean Moore vim is awesome 😎
@kriswachtell
@kriswachtell Жыл бұрын
Great video explaning how to spin up nginx load balancer. One thing that can added is that docker is member of sudo using "sudo usermod -aG docker $USER"
@justinroysdon2630
@justinroysdon2630 3 жыл бұрын
Well spoken. Like the video a lot. Nginx docs make it so complicated. You made this so simple. I love how you just wrote the configs from scratch and explained it. I would recommend in future videos typing out the line and then talking about it so that people can type it out while you speak. Also, have you done a video using nginx and an SSL certificate? I'll search your videos, but if you haven't that would be a great addition.
@hnasr
@hnasr 3 жыл бұрын
Justin Roysdon thanks Justin! Yes this is a 2 hours video discussing nginx 2 Hours NginX Crash Course + Bonus Content (Audio Fixed) kzfaq.info/get/bejne/nsmnYLGbtM6comQ.html
@papesldjnsjkfjsn
@papesldjnsjkfjsn 2 жыл бұрын
@@hnasr it's kinda sad that you made that video members only as it was my only reference for nginx related stuff :(
@propeto13
@propeto13 3 жыл бұрын
okay okay, okay, 'subscribed'!
@HosseinOjvar
@HosseinOjvar Жыл бұрын
Hussein a man with energetic voice ;)
@hicalls
@hicalls 4 жыл бұрын
Hello Hussein, thanks for your tutorial. is there any configuration if we config this through public cloud such as GCP or AWS ? do you ever config it ?
@jdcarter157
@jdcarter157 2 жыл бұрын
anybody else get a 502 bad gateway error when trying to load their local host page? or do anyone know what piece im missing ?
@YGNCode
@YGNCode 4 жыл бұрын
I use to deploy web applications on Digital Ocean VPC. Normally, I had one LB which is one server. And 2 applications that are on separate on different servers. So, a total of 3 servers. Can you please explain how it gonna archive with docker?
@NeroNuke
@NeroNuke Жыл бұрын
how would i make it not round robin. is there a way to do it using subdomains?
@muhammedadel9673
@muhammedadel9673 4 жыл бұрын
Are there any pros/cons to running ngnix as docker image vs running it at host natively? like whether it's good if it fails for some reason but the the server is still reachable (i know you can configure it to auto restart but it can still fail that)
@hnasr
@hnasr 4 жыл бұрын
Excellent question, it really depends on your architecture and management. If you have NginX as a container spinning up a new container is always faster than spinning up a completely new HOST (VM or physical) with OS and all that bloat just to spin up NginX. That being said managing containers is an extremely difficult problem and an infrastructure cost that is why Kubernetes and Mesos exist. If you decided to host NginX yourself in VMs. Running Docker in a single host with multiple containers is still prune to a single point of failures. if the host fails all your containers are dead. So naturally, you will need another backup host with backup containers and you start which increases your infrastructure cost. It might be easier just to run NginX natively on your host but if you are running multiple services and stuff on the same HOST nginx might starve and can't serve your requests. A problem that doesn't exist in containers because of resource isolation (each container gets a cut of RAM/CPU) So yes in summary Pros & cons of everything, containers are lightweight, faster to spin up, isolated but costly to maintain and require multiple hosts (pods) anyway and definitely require a container orchestrator like K8 to manage the mess and most probably you will start needing a service mesh which will just double your infrastructure costs. Alternatively, you can have some VMs and run NginX natively on them, but you will eat the cost of slow scaling .. I hear microVMs is a think now that gives you isolation. If you have few clients probably not a bad idea to start this way and avoid the complexity of microservices.
@cserajesh
@cserajesh 2 жыл бұрын
Just need to make sure one thing what did you write in the nginx.conf file
@MrCobraq
@MrCobraq 2 жыл бұрын
I like how eccentric you are
@user-nf7xi8xi4t
@user-nf7xi8xi4t Ай бұрын
will this conf work for tcp ?
@ash-faque
@ash-faque Жыл бұрын
Its nice that youtube got x2 option
@alexbhattaraicruze
@alexbhattaraicruze 4 жыл бұрын
Wouldn't you have, in the end, localhost:2222, localhost:3333 and localhost:8080 running? Is it possible for port 2222 and 3333 not be accessible meanwhile port 8080 be running?
@hnasr
@hnasr 4 жыл бұрын
Good question! Yes it is possible in this case the proxy is available but none of backends are. In this case the proxy will reply with 5xx error usually service unavailable error.
@user-gx6zy3gh6t
@user-gx6zy3gh6t 7 ай бұрын
How can I join the membership?
@mr.chowdhury2737
@mr.chowdhury2737 3 жыл бұрын
if i don't use http at proxy_pass what will be happened?
@vaibhavhiwase5462
@vaibhavhiwase5462 2 жыл бұрын
How can i load Balance post request
@najeebshhade9572
@najeebshhade9572 3 жыл бұрын
Hi Hossein It was a great video I have an issue : when I run the docker its write : host not found in upstream "najeebs-virtual:2222" in etc/nginx/nginx conf:3 when I run the server browser it's write the nginx server is working .... I think that the nginx.conf didn't replace as you said ... what do you think?
@hnasr
@hnasr 3 жыл бұрын
It looks like you wrote nginx.conf but your host cannot be found. You sure you have the host up and running?
@najeebshhade9572
@najeebshhade9572 3 жыл бұрын
@@hnasr Umm sorry I'm really jonior in linux, now I found out that I didn't make any host in my VM , so I tryed to write localhost:2222 and localhost:3333 And it runed the docker , the problem is that in the google browser write what it is written in the index.html in usr/shared/nginx/nginx.html ... Witch is my hostname vm it should be that or something else? And if it is true could I create more than one host name in my VM ?
@adambaker1777
@adambaker1777 3 жыл бұрын
Hey Hussein, great video. Like some others in the comments, I am experiencing a 502 bad gateway error. I attempted to map to my private IP in the upstream of the nginx.conf file, but the 502 error persisted. I can get a response in the browser from my upstream servers using the same IP, but I cannot get them to be served by the load balancer. For context I am running on Docker Desktop for Windows, I don't know if that matters. Any thoughts here?
@hnasr
@hnasr 3 жыл бұрын
Bad gateway means that you can reach the load balancer but the load balancer can't reach the backend for some reason. Try bashing into the container running nginx and ping the backend ip.
@adambaker1777
@adambaker1777 3 жыл бұрын
@@hnasr Thanks for the super quick reply, I really appreciate it. You were right, I could not ping my local IP from inside my docker container. After figuring this out it took me a while, but I found that you can route traffic to host.docker.internal inside the Nginx file and it will route to the localhost. So I am now happy to report that the load balancer is up and running. Really appreciate your content and responsiveness Hussein. Keep it up. Details about host.docker.internal for others experiencing the same problem -- stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach
@xmassacrex4255
@xmassacrex4255 Жыл бұрын
@@adambaker1777 hey Adam, can you help me? i keep facing the 502 problem
@mr.chowdhury2737
@mr.chowdhury2737 3 жыл бұрын
but the all three port is open 2222 and 3333. outside people can access those port.
@sanjaycharles
@sanjaycharles 3 жыл бұрын
The tutorialwas simple mate..but when I tried it out...it was prompting an error
@kerolloz
@kerolloz 4 жыл бұрын
Thank you Hussein. Nice video. Here is my implementation: github.com/kerolloz/loadbalancer-nginx-nodejs-example.
@hnasr
@hnasr 4 жыл бұрын
Well done!
@kerolloz
@kerolloz 4 жыл бұрын
Thanks to your great videos ✨
@kumarvadivel4328
@kumarvadivel4328 3 жыл бұрын
hey dude so you never assign the ports for the nodejs instances how does it maps the nodejs ports????
@burloiumarian2665
@burloiumarian2665 Жыл бұрын
@@kumarvadivel4328 1 year later , i guess it takes the default port 5000 ? but i don't get how to they all run on port 5000
@markistheone947
@markistheone947 4 жыл бұрын
Meh! Good but without dropping one of the web servers, you're not actually showing if load balancer works or not, also it would be way better with three web servers.
@tonymathewt
@tonymathewt Жыл бұрын
proxy_pass ❤
Is this the BEST Reverse Proxy for Docker? // Traefik Tutorial
21:57
Christian Lempa
Рет қаралды 507 М.
Doing This Instead Of Studying.. 😳
00:12
Jojo Sim
Рет қаралды 23 МЛН
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 8 МЛН
Load balancing in Layer 4 vs Layer 7 with HAPROXY Examples
37:33
Hussein Nasser
Рет қаралды 160 М.
What is a Server? (Deepdive)
17:51
LiveOverflow
Рет қаралды 172 М.
Here's why you need Nginx as a Reverse Proxy for your Node.js app
10:17
Software Developer Diaries
Рет қаралды 21 М.
Using docker in unusual ways
12:58
Dreams of Code
Рет қаралды 429 М.
Flask Load Balancing Using Nginx and Docker
18:39
DevGuyAhnaf
Рет қаралды 33 М.
Load Balancing with NGINX
30:03
NGINX
Рет қаралды 62 М.
The cloud is over-engineered and overpriced (no music)
14:39
Tom Delalande
Рет қаралды 529 М.
98% Cloud Cost Saved By Writing Our Own Database
21:45
ThePrimeTime
Рет қаралды 341 М.
This Docker Compose UI is amazing! // Dockge
13:08
Christian Lempa
Рет қаралды 99 М.
Это iPhone 16
0:52
Wylsacom
Рет қаралды 1 МЛН
iPhone socket cleaning #Fixit
0:30
Tamar DB (mt)
Рет қаралды 18 МЛН
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 7 МЛН
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 65 МЛН