Public Repository

Last pushed: 2 years ago
Short Description
Image with nginx installation.
Full Description

How to Use

Create a Dockerfile in the root of your project with a configuration like the following.

FROM jwzirilli/nginx
# Copy your nginx
COPY ./path/to/mysite.conf /etc/nginx/sites-enabled/mysite.conf
# Copy your static assets
COPY ./static-assets /usr/share/nginx/html
# Expose the port nginx is listening on
EXPOSE 80

 
Then, build the image and run the container.

$ docker build -t my-nginx .
$ docker run -d -p 80:80 my-nginx

 

Running with jwzirilli/nodejs

If you would like to setup nginx as a load balancer for node containers, there are two ways to do it. You could connect nginx to the node containers using port mappings, or you can connect them using docker's linking system. If you would like to expose the node ports, use the first option, if not (recommended), use the second. You can read more here.

Option 1: Using network port mappings

First, build your node image following the steps from jwzirilli/nodejs.

When you run the containers, expose the ports and make sure to give your nodes unique names. E.g.

$ docker run -dP --name my-node-app1 my-node-app
$ docker run -dP --name my-node-app2 my-node-app
$ docker run -dP --name my-node-app3 my-node-app
$ docker run -dP --name my-node-app4 my-node-app

 
Then, setup an nginx site that looks like the following:

mysite.conf

upstream project {
  server my-node-app1:3000;
  server my-node-app2:3000;
  server my-node-app3:3000;
  server my-node-app4:3000;
}

server {
  listen 80 default;

  location / {
    proxy_pass http://project;
  }
}

 
Then setup your nginx Dockerfile like so:

FROM jwzirilli/nginx
COPY ./path/to/mysite.conf /etc/nginx/sites-enabled/mysite.conf
EXPOSE 80

 
Finally, build the image and run the container:

$ docker build -t my-nginx .
$ docker run -d -p 80:80 my-nginx

 

Option 2 (recommended): Using Docker's linking system

First, build your node image following the steps from jwzirilli/nodejs.

When you run the containers, do not expose the port and make sure to give your nodes unique names. E.g.

$ docker run -d --name my-node-app1 my-node-app
$ docker run -d --name my-node-app2 my-node-app
$ docker run -d --name my-node-app3 my-node-app
$ docker run -d --name my-node-app4 my-node-app

 
Then, setup an nginx site that looks like the following:

mysite.conf

upstream project {
  server my-node-app1:3000;
  server my-node-app2:3000;
  server my-node-app3:3000;
  server my-node-app4:3000;
}

server {
  listen 80 default;

  location / {
    proxy_pass http://project;
  }
}

 
Then setup your nginx Dockerfile like so:

FROM jwzirilli/nginx
COPY ./path/to/mysite.conf /etc/nginx/sites-enabled/mysite.conf
EXPOSE 80

 
Finally, build the image and run the container, linking all node containers:

$ docker build -t my-nginx .
$ docker run -d -p 80:80 --link my-node-app1 --link my-node-app2 --link my-node-app3 --link my-node-app4 my-nginx

 

Docker Pull Command
Owner
jwzirilli

Comments (0)