Setup an Nginx Proxy for a Node.js App with Docker

Mark Shust
InstructorMark Shust
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 2 years ago

Learn how to setup an Nginx proxy server with Docker that sits in front of a Node.js app. You can use a proxy to control the flow of frontend requests hitting your app, as well as to achieve better performance and scalability. We'll create a sample Node.js app, configure a default Nginx configuration file for proxying web requests, build both Node.js and Nginx Docker images, and learn how to link everything up and get it running with Docker specifics.

FED
FED
~ 6 years ago

Super grateful for this video, as I'm unfamiliar with Nginx and have had a tough time finding good learning resources.

Given my unfamiliarity with Nginx and Docker, I had a pretty tough time following along with this video. I think it might be helpful to suggest some prerequisite knowledge that the viewer should have prior to watching. Ideally, there could even be some references to other egghead.io videos that the viewer might find helpful to watch beforehand. Two things that I found confusing was what the path foo/node pointed to when you ran docker build and the value you passed to FROM in the Dockerfile mhart/alpine-node. I think that points to the presenter's Docker image (not sure if that's the correct term), but I'm not positive.

Larry Botha
Larry Botha
~ 6 years ago

--link is deprecated and user-defined networks are the now recommended way of networking containers. I added notes for this video on Github, and added notes on creating a user-defined network too: https://github.com/larrybotha/eggheadio-start-using-docker-containers/blob/master/05-setup-nginx-proxy-for-node-app.md

Sergey
Sergey
~ 5 years ago

Setup can be simplified if you use docker-compose. Create docker-compose.yml file in the root folder with following contents:

https://gist.github.com/szarouski/1974f80d72770c242fbde7fbfde90484

then from command line run docker-compose up. You're done. No need to run docker build, give names to containers, use long list of parameters

flyingwip
flyingwip
~ 5 years ago

I get this error:

ERROR: for nginx-poc Cannot start service nginx-poc: driver failed programming external connectivity on endpoint ngxapp_nginx-poc_1 (3dc69647a605f3f27225ee4dfdff7f3bfc07f9c251680f94ec9cfdf9f422c8af): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE) ERROR: Encountered errors while bringing up the project.

J. Matthew
J. Matthew
~ 5 years ago

I think it might be helpful to suggest some prerequisite knowledge that the viewer should have prior to watching. Ideally, there could even be some references to other egghead.io videos that the viewer might find helpful to watch beforehand.

This video is near the end of the following playlist, which I have found extremely helpful and which answers that exact need: https://egghead.io/playlists/docker-fundamentals-0cb53b55. In my opinion this playlist serves as a de facto "Getting Started with Docker" course.

Two things that I found confusing was what the path foo/node pointed to when you ran docker build and the value you passed to FROM in the Dockerfile mhart/alpine-node. I think that points to the presenter's Docker image (not sure if that's the correct term), but I'm not positive.

foo/node is not a path, despite appearances, but simply the name given to the image created by the command. The full command is docker build -t foo/node ., which builds an image from the Dockerfile in the current directory (indicated by that trailing dot), and names it whatever is passed to the (optional?) -t- flag, in this case foo/node. Naming images makes it easier to refer to them later.

You are on the right track with the value passed to FROM. Each Docker image must be built on another Docker image, so every Dockerfile starts with a FROM command indicating which other image will serve as the starting point of the current image. The presenter presumably didn't create mhart/alpine-node; rather it is a publicly-available image that supplies some version of node for use in Docker. That's what enables the Dockerfile to end with a node command: CMD node index.js

I learned all this from the aforementioned playlist.

J. Matthew
J. Matthew
~ 5 years ago

Setup can be simplified if you use docker-compose.

You are right, but it's valuable to learn how to do it this way and understand what's really going on before leveraging the syntactical sugar that Docker Compose provides.

Devin Rhode
Devin Rhode
~ 7 months ago

I guess this material is too outdated. --link is deprecated and legacy now. https://docs.docker.com/network/links/

Markdown supported.
Become a member to join the discussionEnroll Today