Public Repository

Last pushed: a year ago
Short Description
Alpine image with Nginx.
Full Description

Tags & Dockerfile

What is Nginx?

Nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server.

Structure

Nginx is installed under /nginx

/nginx # tree -d
.
├── etc
├── html
├── log
├── run
└── tmp

5 directories

Usage

Basic usage

Start a basic container with Nginx running on it.

$ docker run -d --name my-nginx -p 80:80 jfusterm/nginx

Then go to http://localhost or http://ip and check that Nginx is running.

Using your static content

Serve your static content mounting a directory into the container.

$ docker run -d --name my-nginx -p 80:80 -v /dir/my-static-content:/nginx/html:ro jfusterm/nginx

Using your own nginx.conf

Use your own Nginx configuration.

$ docker run -d --name my-nginx -p 80:80 -v /dir/nginx.conf:/nginx/etc/nginx.conf:ro jfusterm/nginx

Building your own image

Build your own personalized image. First create your Dockerfile

FROM jfusterm/nginx

COPY my-static-content /nginx/html
COPY nginx.conf /nginx/etc
COPY my-ssl-certs /nginx

VOLUME ["/nginx/html","/nginx/logs"]

Build your image out of this Dockefile.

$ docker build -t my-image .

Once built, you can create a container using your new image.

$ docker run -d --name my-nginx -p 80:80 -p 443:443 my-image

Nginx with PHP-FPM

If you want to run PHP code and you have a PHP-FPM service already running, you can run this Nginx image passing an environmental variable with the IP of the service.

$ docker run -d --name my-nginx -p 80:80 -p 443:443 -v /dir/code:/nginx/html:ro -e PHPFPM=192.168.42.1 jfusterm/nginx

In this example, Nginx will forward all the PHP requests to the PHP-FPM server located in 192.168.42.1:9000. If multiple PHP-FPM servers are available, you can distribute the load across them passing the IPs separated with a ,.

$ docker run -d --name my-nginx -p 80:80 -p 443:443 -v /dir/code:/nginx/html:ro -e PHPFPM=192.168.42.1,192.168.42.2 jfusterm/nginx

In both cases Nginx will generate the proper configuration files to run properly.

If you want a PHP-ready web server, you can use Docker Compose to configure your environment. As an example, save the following configuration in a docker-compose.yml.

version: '2'
services:
  web:
    image: jfusterm/nginx:1.9.14
    container_name: my-nginx
    ports:
    - "80:80"
    - "443:443"
    volumes:
    - php_code:/nginx/html:ro
    depends_on:
    - php-fpm
    environment:
      PHPFPM: php-fpm
    links:
    - php-fpm
    networks:
    - php_net
  php-fpm:
    image: jfusterm/php-fpm:7.0.5
    container_name: my-php-fpm
    ports:
    - "9000:9000"
    volumes:
    - php_code:/nginx/html:ro
    networks:
    - php_net

networks:
  php_net:
    driver: bridge

volumes:
   php_code:

Once you have the file, run it.

$ docker-compose up -d
Docker Pull Command
Owner
jfusterm