[00:02] at the difference between nginx and traffic for setting up a reverse proxy with docker for those not familiar with the 2 nginx originally released in 2004. according to a netcraft web server survey done in [00:16] to a netcraft web server survey done in january 2022 32.3 websites are using traffic on the other hand is relatively new founded in 2016 it's a cloud native application that aims to take out the complexity of designing deploying and [00:29] operating applications so first we're going to have a look at setting up nginx as a reverse proxy in my docker compose file here i've got the default nginx image which is running on port 80. [00:42] i also have the who am i image and which is also going to be running on port 80 and the ghost blogging image which natalie runs on port 2368 so you can see here i'm overwriting the default.com file [00:56] with my own so the default.com file is set up here locations set up i have one for who am i and i have the platform you don't need to worry too much about [01:11] settings and you can copy and paste them from my github which there's a link in the description of this video you'll notice the proxy pass parameter this works whenever the docker containers are running within the same [01:23] containers are running within the same docker network and see what it looks like so i'm going to write docker compose [01:39] minus f and the name of my file and up go to our browser and if we go to our who am i you should see it's running [01:53] it gives you all the information about the browser and everything else the browser and everything else and now similarly if we go to ghost [02:09] we didn't have nginx running as a reverse proxy we'd have to have these set up in different ports so say this is who am i which is running on port 80 but we might have other services so let's run this on port 8080 [02:22] so let's run this on port 8080 and for ghost we're running on port 2368 so we might have to run this on port 3001 so having a reverse proxy setup allows us to easily configure multiple services [02:35] and have them running under different subfolders or even sub-domains now the downside of nginx is there's no out-of-the-box way to start new services say i wanted to add another blog to this docker compose file [02:48] we copy this ghost one let's call it coach two to be able to set this up inside nginx we'd also have to copy our ghost location set this up as ghost 2 [03:05] and then restart our service naturally the community's found a way of getting around this limitation if you do want to use nginx i suggest you check out this github nginx proxy which allows you to automatically pick [03:17] now if we want to change our docker compose to use nginx proxy compose to use nginx proxy first we need to change the image [03:30] volumes to use docker sock so that our container can access the other docker container can access the other docker containers on the system variables on each of our containers so that nginx proxy knows what to do here [03:46] we have on our whoa my container can set up the virtual host which in our case is localhost the virtual path which is who am i and the port that the container is running on which is 18 in this case [03:58] and then we're going to do the same for ghost and ghost 2. [04:12] and that's it if we run this is running correctly on each of the ports ports so we have who am i running [04:27] and of course goes to nginx proxy you can see here we've got the docker.sock added so traffic has [04:39] access to the running docker containers instead of environment variables we're using docker labels so traffic knows if a service is to be proxied in a similar way we can set up the port and the path this time using a registered expression [04:52] to specify the path now you also notice that we have port 80 set up for our proxy request and port 8080. now port 8080 is for the dashboard dashboard view so we can see which services are set up [05:06] and running now you can also see i've got a traffic.yml file set up at the moment i'm just using the defaults that are specified on the docker website but documentation there's a lot more settings there so as before we have who [05:19] am i that's working fine ghost is also pointing to our ghost and lastly on port 8080 we have our dashboard as you can see here you get a nice view of which services have been set up you [05:31] can see which routers are running and you see here we've got our one working for ghost as well as one for who am i there isn't much you can actually nice overview of all the services and also if [05:43] like me you don't like lots of white services you can use the dark theme as the last thing i want to show you is around docker networks at the moment i've only shown services configured in the same docker compose file however you [05:56] docker compose files and still have them running through one instance of traffic or nginx proxy first you need to create the docker network we do this with network create and it's called our network home [06:11] then we need to add that network to our docker compose files then the name of our network which in this case is home [Music] true [06:30] each of our services so let's do networks [06:51] services set up without traffic here so we've just got another whoa my instance and another ghost this time it's called who am i two and ghost two so again we're going to add [07:03] so again we're going to add add this network to each of them so now we need to start each of these up and then we should be able to see them [07:15] and then we should be able to see them coming through in traffic are in that file and now i'm going to create another [07:31] console and start the one that's just got the services in it dashboard let's give this a refresh [07:48] you can see it's coming through on who well and we'll just double check that these work go who am i refresh that one got my two [08:01] working fine ghost ghost and ghost two useful there's a link below to the github so you can find the code for this [08:16] and if you found this useful please click subscribe and like the video and this is quite a new channel so really help me out thank you