How to Host Multiple Docker Containers on a Single Server with Nginx Reverse Proxy?

Поделиться
HTML-код
  • Опубликовано: 23 окт 2024

Комментарии • 135

  • @yuvvrajkperson
    @yuvvrajkperson 2 года назад +14

    No beating around the bush, straight to the point, easy examples, and answering questions in the comments. You sir are amazing

  • @hostinggeek
    @hostinggeek 2 месяца назад +1

    This is by far the best nginx proxy tutorial I've seen in many years of doing this. It should be the standard.

  • @brendang8610
    @brendang8610 3 года назад +16

    I have been stuck for so long trying to configure the server blocks for my docker droplet. For a beginner like me who until today hadn't even heard of a server block, this was so much more informative than the digital ocean documentation on setting up nginx!!

    • @bobbyiliev_
      @bobbyiliev_  3 года назад +2

      Hey Brendan, no problem at all! Happy to hear that you've found this helpful!

  • @josephjwilk
    @josephjwilk Год назад

    Thank you so much for this. I have struggled with this, and with some tweaks to the firewall and certbot, it's finally working! Thank you again for the straightforward and uncomplicated directions.

  • @tsivanathan
    @tsivanathan 4 года назад +7

    Simple and straight to the point, thanks a lot sir!!!!

    • @bobbyiliev_
      @bobbyiliev_  4 года назад

      Thank you for the nice feedback!

  • @dayumnson9769
    @dayumnson9769 4 года назад +5

    Instantly subscribed, what a clear ans straigth forward tutroial. Thanks man!

    • @bobbyiliev_
      @bobbyiliev_  4 года назад

      Thanks a lot! Appreciate that! 🙌

  • @hakanbilgin9532
    @hakanbilgin9532 4 года назад +3

    Thanks for a simple bare-bone example! Do you have suggestion on how to "hot-swap" to an updated image without downtime?

    • @bobbyiliev_
      @bobbyiliev_  4 года назад

      Hey Hakan, thanks for the positive feedback! No, I don't have that at the moment but it is a great idea for a new video! I will put it in my to-do list 🙌

  • @PabloBecerra
    @PabloBecerra Год назад +1

    Nice tutorial! Thank you! I was wondering if it's possible to do the same, but with php-fpm containers. Which would be the right configuration for nginx in this case?

  • @MarlonSena
    @MarlonSena Год назад +1

    Tks, Bobby! :)

  • @mamirazmi
    @mamirazmi Год назад +2

    Sorry i quite new to docker deployment, can i know how to make it ssl and https with 443

  • @brandonb7979
    @brandonb7979 2 года назад +2

    Did you edit the default file any? Also subscribed, great video!

    • @bobbyiliev_
      @bobbyiliev_  Год назад +1

      Thank you! No, I just used the default Nginx config, but I had my subdomains pre configured to point to my server before the video

  • @GkmVlogs2019
    @GkmVlogs2019 Год назад +1

    How to access container without changing end point url... for example I have an web api. I will run my web api as 2 container like instance..I want to access.

  • @shadyjeff12
    @shadyjeff12 Год назад +2

    Can you make a tutorial on how to apple letsencypt certificates to those domains?

  • @zeerar
    @zeerar 2 года назад +3

    Best tutotrial

  • @yongquanrao7398
    @yongquanrao7398 Год назад +1

    this is really helpful. thanks for sharing.

  • @FrankoMtz
    @FrankoMtz Год назад

    Hi, nginx its instaled on your "server" ? or its like an other container?, thanks for the tuto

  • @aloktechie7981
    @aloktechie7981 2 года назад

    Thank you so much for the video. I have my intel NUC setup and i have domain name as well, do we need to also do port forwarding in router or Nginx will take care of it ?

  • @MohammedAbdulatef
    @MohammedAbdulatef 4 года назад +5

    Thank you so much, I have learned a lot from you.

  • @soufianeodf9125
    @soufianeodf9125 2 года назад +4

    how you can add ssl certificate for those subdomains ?

    • @bobbyiliev_
      @bobbyiliev_  Год назад

      You can do that with a free Let's Encrypt SSL and certbot:
      www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-20-04

  • @FASHIONmanTV1
    @FASHIONmanTV1 2 года назад +1

    Perfect

  • @santiagoale6232
    @santiagoale6232 9 месяцев назад

    This video sir is just perfect, thank you

  • @jhoanmartinezsilva2609
    @jhoanmartinezsilva2609 Год назад

    Are the domains registered?
    The nane of the file must be the same as the domain?
    Thanks a lot!

  • @juliokavege9772
    @juliokavege9772 Год назад

    Nice video that help me so much. But it seen the reverse proxy i configure doesn't work. It doesn't work unless i type the port of my app. My context is : I dockerize a laravel app with 3 services(app, db , webserver(which is nginx)) and it host on hostinger vps.

  • @adremides
    @adremides 4 года назад +4

    Why not run the reverse proxy on a container too?

    • @bobbyiliev_
      @bobbyiliev_  4 года назад +1

      That is a good point! Thanks!

  • @bobbyiliev_
    @bobbyiliev_  Месяц назад +1

    In case that you are just getting started with Docker, I could suggest this free eBook here too:
    devdojo.com/bobbyiliev/free-introduction-to-docker-ebook

  • @lifetillhope5733
    @lifetillhope5733 2 года назад

    what about if i use nginx server as a container. mean my app deploy on one container and i have second container called nginx how i configure my nginx container as a reverse proxy? hope you understand my question. kindly reply

  • @jonnetg
    @jonnetg 2 года назад +1

    Thank you so much!! Excellent Example!

    • @bobbyiliev_
      @bobbyiliev_  Год назад

      Thank you! Happy to hear that it was helpful!

  • @AnanyaDasgupta-t5k
    @AnanyaDasgupta-t5k 2 месяца назад

    I don't have domain name configured for my server. I am trying to achieve the same using public ip. Is that not possible?

  • @shanahjrsuping7344
    @shanahjrsuping7344 4 года назад +2

    Did you also create A records for these domains?

    • @bobbyiliev_
      @bobbyiliev_  4 года назад +5

      Hi Shanah,
      Yes I had the DNS records all pre-configured.

    • @shanahjrsuping7344
      @shanahjrsuping7344 4 года назад +1

      @@bobbyiliev_ Thank you very much!

    • @bobbyiliev_
      @bobbyiliev_  4 года назад

      @@shanahjrsuping7344 No problem at all! Happy to help.

  • @தியான்
    @தியான் 4 года назад +2

    Hi ,can you post cluster management on Docker container like 1 load balancing 2 reachable 3 not reachable ,how do health check

    • @bobbyiliev_
      @bobbyiliev_  3 года назад

      That is a good idea! I will put it in my todo list and might give it a try!

  • @jimmyj.6792
    @jimmyj.6792 4 года назад +2

    Hi thanks for video but how to automate the creation of subdomain when creating a new docker image with port ? It’s a little bit sad to create manually this file for each feature that i want to deploy.
    Thanks for your answer 😀

    • @bobbyiliev_
      @bobbyiliev_  4 года назад +2

      Hi, yes that is a good point! You could try using Docker Compose, or an automation tool like Ansible to automate the manual tasks.

    • @jimmyj.6792
      @jimmyj.6792 4 года назад

      Bobby Iliev how can i integrate it into a pipeline like Jenkins or gitlab ci ?

    • @bobbyiliev_
      @bobbyiliev_  4 года назад +1

      @@jimmyj.6792 I would recommend going through this tutorial here:
      www.digitalocean.com/community/tutorials/how-to-set-up-continuous-integration-pipelines-in-jenkins-on-ubuntu-16-04

  • @vinodhreddy6227
    @vinodhreddy6227 4 года назад +1

    I have a issue... I have three Ubuntu servers and I have 12 microservices. One server I created 4 services. One server one compose I configured four services.. I run I'm able register eureka all servixes... Zull gateway I can able to access fst servers but remaining I'm not able to access based on serviceId... Can I tell me where I done mistake

    • @bobbyiliev_
      @bobbyiliev_  3 года назад

      Hello,
      If you run docker network inspect do you see all services inside that network?

  • @hanss2006
    @hanss2006 Год назад +1

    Nice

  • @ThisIsmeIrving
    @ThisIsmeIrving 4 года назад +1

    does this works even if I'm using like 3 docker containers to run a single app with wordpress? I want to use nginx as a load balancer between the containers to run wordpress.

    • @bobbyiliev_
      @bobbyiliev_  4 года назад +1

      Yep, this should work with 3 WordPress containers as well. You might have to add some extra proxy rules in the Nginx Server Blocks to make it work for WordPress

  • @vietnguyen6228
    @vietnguyen6228 3 года назад +1

    Thank you my friend!

    • @bobbyiliev_
      @bobbyiliev_  3 года назад

      No problem at all! Happy to hear that this was helpful!

  •  5 месяцев назад

    thank you so much for the video, hope this is not a stupid question , is this information in the video valid in 2024 ?

  • @Ombibulous_Bluegrass
    @Ombibulous_Bluegrass 3 года назад +1

    Great video, thanks

    • @bobbyiliev_
      @bobbyiliev_  3 года назад

      No problem at all! Happy to hear that it was helpful!

  • @zeerar
    @zeerar 2 года назад +1

    nice

  • @djcaesar9114
    @djcaesar9114 2 месяца назад

    The big problem is that you have to manage the ports, and it will be difficult with multiple projects having their own team.

  • @soufianeodf9125
    @soufianeodf9125 2 года назад +1

    Thanks for the video, really helped

  • @aswanthbabu1202
    @aswanthbabu1202 2 года назад

    how did you enable the sub-domian feature can we configure this with out name server and local machine ?

    • @bobbyiliev_
      @bobbyiliev_  Год назад

      Hey! For the example I created the DNS records in my DNS zone beforehand, but you could use your hosts file on your local machine if it is just for testing too

  • @natural8471
    @natural8471 6 месяцев назад

    Thanks ! It's very helpful

  • @pavelh2518
    @pavelh2518 4 года назад +1

    You can also run nginx as a docker container right?

  • @adithyakannan23
    @adithyakannan23 3 года назад +1

    I need the docker to point a domain I have, How to go for that ?

    • @bobbyiliev_
      @bobbyiliev_  3 года назад +1

      Hi there, I setup A records for each subdomain name to point to the Droplet's IP address before the video. Here is how you could do that:
      www.digitalocean.com/docs/networking/dns/how-to/manage-records/

  • @salarkamjoo3669
    @salarkamjoo3669 10 месяцев назад

    perfect tutorial !

  • @Ashish447
    @Ashish447 3 года назад

    Hi, I ran into an issue while implementing this great solution. Let's say I run the Nginx server as a docker container and it remains up.
    Now I have a microservices container(dockerized), and is accessed via Nginx reverse proxy.
    In case when a microservice's container is down for sometime and then restarted, the Nginx throws an upstream error.
    The upstream error occurs even if the container is up and running.
    Would appreciate any solution for this issue

    • @bobbyiliev_
      @bobbyiliev_  3 года назад +1

      Hi there! This sounds like an interesting setup! Indeed running the Nginx service in a Docker container sounds like a better approach in some cases.
      In your Nginx configuration, are you using the Docker container IPs for the `server_block`? It sounds like that the docker container IP changes and then the Nginx service is no longer able to connect to the upstream.
      If this is the case I could suggest 2 things:
      - Make sure to create a docker network and use the container names rather than the container IPs: www.digitalocean.com/community/questions/how-to-ping-docker-container-from-another-container-by-name
      - Make sure to specify a restart policy so that if a service crashes, it would be restarted again: www.digitalocean.com/community/questions/how-to-start-docker-containers-automatically-after-a-reboot
      Finally if none of this helps, I would recommend checking your container logs for some more information on what is wrong: docker logs container_id_here
      Hope that this helps!

    • @Ashish447
      @Ashish447 3 года назад +1

      ​@@bobbyiliev_ Thanks for your response.
      I am referring to the containers through their container names. Digging deeper into this issue, looks like an issue not from Nginx.
      What I observed:
      I have two containers, one built on Phoenix-elixir, the other built on Flask-uWSGI.
      This upstream error doesnt occur when I tried stopping and restarting the phoenix container. The issue was specific to the flask container.
      This certainly seems to be an issue somewhere inside uWSGI. Will get back if i found a solution for this :)

    • @bobbyiliev_
      @bobbyiliev_  3 года назад +1

      @@Ashish447 Sounds like a plan! Let me know how it goes!

    • @Ashish447
      @Ashish447 3 года назад

      @@bobbyiliev_ sure!

  • @meghnamishra6659
    @meghnamishra6659 4 года назад

    Hey if have two node Js file one for server and another for client who are communicating with same port how to create docker image for DAT?

    • @bobbyiliev_
      @bobbyiliev_  4 года назад

      Hello,
      In this case I could suggest following the steps here on how to build a Node.js application with Docker:
      www.digitalocean.com/community/tutorials/how-to-build-a-node-js-application-with-docker

  • @faisalabdi6350
    @faisalabdi6350 3 года назад

    i tried to follow this on a Centos vm, when i browse to docker1 url, it keeps taking me to welcome centos url page for somereason, i keep having to add the port number still even though i installed nginx

    • @bobbyiliev_
      @bobbyiliev_  3 года назад

      Hi, it sounds like that the Nginx server block configuration that you have is not correct. Feel free to post a question on the DigitalOcean community forum and include your current configuration files:
      www.digitalocean.com/community/questions

    • @faisalabdi6350
      @faisalabdi6350 3 года назад

      @@bobbyiliev_ cool will do.. thanks for your help

  • @Halissonskalee
    @Halissonskalee 4 года назад +1

    Nice! tansks!

    • @bobbyiliev_
      @bobbyiliev_  4 года назад

      No problem! Thank you for the feedback!

  • @தியான்
    @தியான் 4 года назад +1

    Nice 👍

    • @bobbyiliev_
      @bobbyiliev_  3 года назад

      No problem at all! Happy to hear that it helped! 🙌

  • @CarlosWolfram
    @CarlosWolfram 3 года назад

    Me has cambiado la vida y mi hosting poniéndome limites por crear subdominios xD

    • @bobbyiliev_
      @bobbyiliev_  3 года назад

      Hi there, there are a few things you could do in this case:
      * either use actual domain names for each Nginx server block
      * access the containers directly on the port
      * use 1 server block with multiple locations, for example, /app1 /app2 and etc
      Hope that this helps!

  • @sprintwithcarlos
    @sprintwithcarlos 4 года назад +1

    🙌🏽

  • @ibrahimoglu
    @ibrahimoglu 2 года назад +1

    👍

  • @kalitsiadischaritos4685
    @kalitsiadischaritos4685 3 года назад

    Why this way working only with Ubuntu ? I tried also with red hat / centOS, arch , open suse but no results .

    • @bobbyiliev_
      @bobbyiliev_  3 года назад

      Hi there,
      The approach is more or less the same, however of course there are some differences between the different Linux distros. For example to install Nginx on CetnOS you would use dnf or yum and not apt.
      You can follow the steps on how to setup Nginx server blocks on CentOS here:
      www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-on-centos-7

    • @kalitsiadischaritos4685
      @kalitsiadischaritos4685 3 года назад

      @@bobbyiliev_ nope is not that the case.
      I repeat everything again, all installations done properly. Everything working fine but when it comes to serve the app, only Ubuntu is able to serve it. All other distros serve default ngnix page.
      Really strange.
      Anyway could you make one step ahead and add the ssl certificate?

    • @bobbyiliev_
      @bobbyiliev_  3 года назад

      @@kalitsiadischaritos4685 Feel free to post a question on the DigitalOcean community forum here:
      www.digitalocean.com/community/questions
      Make sure to provide as much information as possible including the Nginx server block configuration that you are using.

  • @jiazq
    @jiazq 2 года назад +1

    '-dit' option mean what? it's wired!

    • @bobbyiliev_
      @bobbyiliev_  2 года назад +2

      -d = Detached
      -i = Keep STDIN open even if not attached
      -t = Allocate a pseudo-tty

  • @aravinddas1720
    @aravinddas1720 3 года назад

    Is this method same in the centos environment, if so I'm not getting the URL part could you share the docs I can refer to

    • @bobbyiliev_
      @bobbyiliev_  3 года назад +1

      The Nginx configuration should be the same, but the installation process and the location of the config directory is different.
      You can follow the steps on how to install Nginx on CentOS 7 here:
      www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7

    • @aravinddas1720
      @aravinddas1720 3 года назад

      @@bobbyiliev_ Bro, I thank you for writing me back, just cleared all the configuration, wanted to overcome an issue could you look into it
      error message:-
      nginx: [emerg] PEM_read_bio_X509_AUX("/root/ssl/rnddev.csr") failed (SSL: error:0909006C:PEM routines:get_name:no start line:Expecting: TRUSTED CERTIFICATE)
      nginx: configuration file /etc/nginx/nginx.conf test failed

    • @bobbyiliev_
      @bobbyiliev_  3 года назад +1

      @@aravinddas1720 it looks like that you've added an SSL certificate to the `/root/ssl` folder, I would recommend moving it to /etc/ssl/ instead and then updating the path in your configuration accordingly.

    • @aravinddas1720
      @aravinddas1720 3 года назад

      @@bobbyiliev_ Same error brother after moving to /etc/ssl/

    • @bobbyiliev_
      @bobbyiliev_  3 года назад

      @@aravinddas1720 What is the error that you get when running an Nginx config test with this command:
      sudo nginx -t

  • @pdamiano
    @pdamiano 4 года назад +1

    what about the https ?

    • @bobbyiliev_
      @bobbyiliev_  4 года назад +2

      Hi Damiano, you can add SSL with certbot as described here:
      www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04

  • @georgez8506
    @georgez8506 4 года назад

    Zdravei moje li da me posuvetva6 kak moga pusna wordpress multisite on docker localhost .

    • @bobbyiliev_
      @bobbyiliev_  3 года назад

      Привет, тук има добър пример за това:
      github.com/pie-inc/docker-wordpress-multisite

  • @ugurserhattoy
    @ugurserhattoy 3 года назад

    Why do you need apache?
    So isn't nginx enough to do that?
    Apache + nginx might be sacrificing nginx efficiency... Sounds like running linux on a windows machine.

    • @bobbyiliev_
      @bobbyiliev_  3 года назад +1

      The Apache containers were used only for the demo. You of course have to change them with your own application like NodeJS or whatever you are running Inside the container.

  • @HafeedElbekkaoui
    @HafeedElbekkaoui Год назад

    It's an httpd appache revers server not an Nginx one.

    • @bobbyiliev_
      @bobbyiliev_  Год назад

      Not really, it is an Nginx Reverse proxy, in this case the Apache httpd was just the backend service, but it could be anything

  • @vetorial_data_custom
    @vetorial_data_custom 3 года назад

    0:44
    6:58