Public Repository

Last pushed: 7 months ago
Short Description
Serve content w/ a highly customizable Nginx server; designed for use w/ AWS ElasticBeanstalk! :P
Full Description

Nginx Docker Image

Serve content with a highly customizable Nginx server; designed for use with AWS ElasticBeanstalk! :P

Overview

This is a minimal Docker image for running Nginx in a highly customizable manner, by making use of a bash script with hooks as the container's run command. It's meant primarily as a workaround for AWS ElasticBeanstalk's lack of a way to specify a run command for a Docker container, and is designed for all hosted content and configuration files to be provided via mounted directories.

Base Docker Image

Usage

  1. If you haven't already, install Docker
  2. Pull the latest automated build from DockerHub: docker pull vixlet/nginx:latest
  3. Run the container!

Running the container

### RUN CONTAINER INTERACTIVELY
docker run -it --rm \
    -p 80:80 \
    -v $( pwd ):/var/app \
    -v $( pwd )/conf.d:/etc/nginx/conf.d \
    --name "vixlet-nginx-example" \
    vixlet/nginx:latest

### RUN CONTAINER IN THE BACKGROUND
docker run -d \
    -p 80:80 \
    -v $( pwd ):/var/app \
    -v $( pwd )/conf.d:/etc/nginx/conf.d \
    --name "vixlet-nginx-example" \
    vixlet/nginx:latest

### RUN CONTAINER IN THE BACKGROUND FOR LOCAL DEVELOPMENT
docker run -d \
    -p 80:80 \
    -v $( pwd ):/var/app \
    -v $( pwd )/conf.d:/etc/nginx/conf.d \
    -e "DOCKER_WATCH=on" \
    --name "vixlet-nginx-example" \
    vixlet/nginx:latest

Configuring Nginx

Mount a directory containing your Nginx site configuration files to either /etc/nginx/conf.d or /etc/nginx/sites-enabled.

Nginx loads the configuration files in the following order:

  • /etc/nginx/conf.d/*.conf
  • /etc/nginx/sites-enabled/*.conf

Setting a script hook

A custom pre-start script can be provided to handle any pre-start tasks (such as rewriting Nginx configuration files with environment variable values, which can only be done at run-time).

Note that any pre-start script must not start any other persistent processes or invoke Nginx itself!

To use a custom pre-start script, simply provide an executable file in your working directory named docker-prestart.sh (or set the DOCKER_PRESTART_SCRIPT environment variable to the filepath of the desired script) and the Docker container will automatically invoke it immediately prior to starting the Nginx process.

Supported environment variables

DOCKER_PRESTART_SCRIPT

  • Path to script to run immediately before Nginx
  • default: "/var/app/docker-prestart.sh"

DOCKER_WATCH

  • Enable when other processes can change files hosted by Nginx (such as gulp watch); disables sendfile, tcp_nopush, and tcp_nodelay directives
  • default: ""
  • enabled: "on"

License

© 2014, 2015 VIXLET CA LLC admin@vixlet.com

The “ISC” license:

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Docker Pull Command
Owner
vixlet

Comments (0)