DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Automated Testing Lifecycle
  • Docker and Kubernetes Transforming Modern Deployment
  • Using Open Source for Data Integration and Automated Synchronizations
  • Mastering Node.js: The Ultimate Guide

Trending

  • Parallelism in ConcurrentHashMap
  • Best Plugins For JetBrains IDEs
  • Deploy a Session Recording Solution Using Ansible and Audit Your Bastion Host
  • Send Your Logs to Loki
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Run NGINX and NGINX Plus in Containers on Photon OS

Run NGINX and NGINX Plus in Containers on Photon OS

Photon OS is a new lightweight Linux distribution from VMware, designed specifically to run containers.

Patrick Nommensen user avatar by
Patrick Nommensen
·
Nov. 30, 15 · Opinion
Like (1)
Save
Tweet
Share
5.29K Views

Join the DZone community and get the full member experience.

Join For Free

By Michael Pleshakov for the NGINX Blog.  

Photon OS supports multiple container specifications, including Docker, rkt, and Pivotal Garden. One of the goals of Photon OS is to provide high performance when running on VMware vSphere. It comes with tdnf, a new yum-compatible package manager for efficient lifecycle management. Photon OS also supports rpm-OSTree, which lets you perform versioned atomic upgrades of a file-system tree across all Photon OS instances and supports an rpm-based package manager for controlling the state of packages in the tree.

Photon OS is in a technical preview stage. It is released as open source software with source code and documentation available in a Github repository.

This post shows how simple it is to run the open source NGINX software and NGINX Plus in a Docker container on Photon OS. After explaining how to install Photon OS, we provide separate instructions for NGINX and NGINX Plus.

We assume that you are familiar with Docker. To get started with Docker, see the guide for your base operating system:

  • Get Started with Docker for Linux
  • Get Started with Docker for Mac OS X
  • Get Started with Docker for Windows

For a good introduction and instructions on how to run NGINX and NGINX Plus in Docker on any type of Docker host, see the Deploying NGINX and NGINX Plus with Docker blog post.

Installing Photon OS

You can start using Photon OS either by importing an OVA file into your virtualization software or by installing Photon OS from an ISO image. VMWare also provides experimental native images for Amazon Web Services, Google Cloud Environment, and Microsoft Azure. For detailed installation instructions, visit the Photon OS wiki.

Note: By default the Docker daemon is not started at boot time. To start the daemon, run this command:

# systemctl start docker

Running NGINX with Photon OS

Once our Photon OS instance up and running, we can start NGINX in a Docker container. (For instructions for NGINX Plus, see the .) Run this command:

# docker run --name mynginx -p 8080:80 -d nginx

We map port 80 inside the container to port 8080 on our Photon OS host. After the NGINX image is pulled from Docker Hub, the NGINX container starts.

Now let’s check that NGINX is indeed running by running a curl command and verifying that we see the text of the default NGINX welcome page:

# curl localhost:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

Running NGINX Plus with Photon OS

Compared to NGINX, running NGINX Plus in a Docker container requires an additional step: we need to build an NGINX Plus container image, which is not available from Docker Hub.

Here’s a Dockerfile for building the image, using Ubuntu 14.04 as the base image. You need to put the nginx-repo.crt and nginx-repo.key files from your NGINX Plus subscription or trial in the same folder as the Dockerfile.

FROM ubuntu:14.04

MAINTAINER NGINX Docker Maintainers "docker-maint@nginx.com"

# Set the debconf frontend to Noninteractive
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections

RUN apt-get update && apt-get install -y -q wget apt-transport-https

# Download certificate and key from the customer portal (https://cs.nginx.com)
# and copy to the build context
ADD nginx-repo.crt /etc/ssl/nginx/
ADD nginx-repo.key /etc/ssl/nginx/

# Get other files required for installation
RUN wget -q -O /etc/ssl/nginx/CA.crt https://cs.nginx.com/static/files/CA.crt
RUN wget -q -O - http://nginx.org/keys/nginx_signing.key | apt-key add -
RUN wget -q -O /etc/apt/apt.conf.d/90nginx https://cs.nginx.com/static/files/90nginx

RUN printf "deb https://plus-pkgs.nginx.com/ubuntu `lsb_release -cs` nginx-plus\n" > /etc/apt/sources.list.d/nginx-plus.list

# Install NGINX Plus
RUN apt-get update && apt-get install -y nginx-plus

# forward request logs to Docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log
RUN ln -sf /dev/stderr /var/log/nginx/error.log

EXPOSE 80 443

CMD ["nginx", "-g", "daemon off;"]

To build the image we run:

# docker build -t nginxplus .

Run this command to verify the image built successfully (it appears on the first line of the sample output):

# docker images
REPOSITORY       TAG              IMAGE ID         CREATED          VIRTUAL SIZE
nginxplus        latest           f0dfff373cf3     37 seconds ago   229 MB
nginx            latest           5c82215b03d1     6 days ago       132.8 MB
ubuntu           14.04            a005e6b7dd01     8 days ago       188.3 MB

To start a container using the image, we run:

# docker run --name mynginxlplus -p 80:80 -d nginxplus

Here we map port 80 inside the container to port 80 on the Photon OS host.

We can check if NGINX Plus is serving pages by running the curl localhost command and verifying that it outputs the default NGINX welcome page, as shown above for NGINX.

For more detailed instructions on how to run NGINX and NGINX Plus in a Docker container, including how to build the NGINX Plus Docker image, manage content, and set up NGINX configuration files and logging, see the Deploying NGINX and NGINX Plus with Docker blog post.

Summary

Photon OS is a lightweight Linux container host that is designed for high performance on VMware vSphere. NGINX and NGINX Plus can be easily deployed in a Docker container to deliver your apps in a Photon OS environment.

Want to get started with NGINX Plus? Sign up for a free 30-day trial today.

Docker (software) Plus (programming language)

Published at DZone with permission of Patrick Nommensen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Automated Testing Lifecycle
  • Docker and Kubernetes Transforming Modern Deployment
  • Using Open Source for Data Integration and Automated Synchronizations
  • Mastering Node.js: The Ultimate Guide

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: