---
title: "Provision NGINX on Docker and Increase Server Capabilities"
description: "Learn how to provision a new NGINX on Docker container running on any operating system such as Windows, macOS, or Linux!"
canonical: "https://adamtheautomator.com/nginx-on-docker/"
---

# Provision NGINX on Docker and Increase Server Capabilities

> Learn how to provision a new NGINX on Docker container running on any operating system such as Windows, macOS, or Linux!

Source: https://adamtheautomator.com/nginx-on-docker/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Provision NGINX on Docker and Increase Server Capabilities](https://adamtheautomator.com/wp-content/uploads/2021/07/Getting-Started-with-NGINX-on-Docker.jpg)

# Provision NGINX on Docker and Increase Server Capabilities

[![](https://secure.gravatar.com/avatar/f08b754bc0dce1c76685f6afa93185ecfb6f861fd14f993286e06bba69eaeb8b?s=192&d=mm&r=g)Adam Listek](https://adamtheautomator.com/author/alistek/)20 July 20216 min. read

Categories: [DevOps](/category/devops/)

Tags:[Docker](/tag/docker/)[NGINX](/tag/nginx/)

Table of Contents

*   [Prerequisites](#h-prerequisites)
*   [Provisioning an NGINX on Docker Container](#h-provisioning-an-nginx-docker-container)
*   [Mapping Website Files to a Container](#h-mapping-website-files-to-a-container)
*   [Running a PHP-FPM Application with a Docker NGINX Container](#h-running-a-php-fpm-application-with-a-docker-nginx-container)
*   [Conclusion](#h-conclusion)

Containerizing web server workloads, such as [NGINX](https://nginx.org/), has become common across the modern IT industry. NGINX makes a perfect container workflow and marrying NGINX to Docker is a perfectly logical task.

In this tutorial, you will learn how to provision a new NGINX on Docker container running on any operating system such as Windows, macOS, or Linux!

## Prerequisites

To follow along with this tutorial, be sure you have the following:

*   [Docker Desktop](https://www.docker.com/products/docker-desktop) – This tutorial uses version 3.5.1.
*   Windows 10 – The tutorial uses Windows to run Docker on but the same general steps can also be applied to Linux or macOS.
*   The [Docker engine](https://docs.docker.com/engine/install/) if you’re on Linux.

## Provisioning an NGINX on Docker Container

Let’s get started by first creating a Linux Docker image with NGINX already installed. This tutorial will use a minimal Linux distribution called [Alpine Linux](https://alpinelinux.org/about/) running the latest NGINX version available, which is 1.21.1 in this tutorial.

1\. First, open a terminal session where you will run all of the necessary Docker commands.

2\. Run the `docker pull` command to retrieve, or `pull`, the latest `nginx` image from the [NGINX Docker Hub](https://hub.docker.com/_/nginx) repository using the `mainlin-alpine` branch. The Docker Hub is an open-source repository of Docker Images available to Docker users.

```bash
docker pull nginx:mainline-alpine
```

![Pulling the nginx:mainline-alpine Docker image ](https://adamtheautomator.com/wp-content/uploads/2021/07/Untitled-2021-07-19T105112.974.png)

Pulling the `nginx:mainline-alpine` Docker image

> _Retrieving the latest image is great for development and testing, but it is often a best production practice to specify a specific version such as `docker pull nginx:1.21.0-alpine`._

3\. Next, run the `docker run` command to run a container from the `nginx:mainline-alpine` image.

*   `-i` – This parameter requests an interactive console, which returns internal container output to the terminal.
*   `-t` – Here you ask for a Pseudo-TTY console to the running container which allows the use of the key command `ctrl-c` to exit the interactive container.
*   `--name` – The name of this container run, must be unique for each new container (unless prior containers of the same name are removed).
*   `-p` – What internal to external port to use, which in this case the internal port of `80` should be mapped to the external port of `80`.
*   “image name” – What Docker image to provision the container from, in this case, the previously pulled `nginx:mainline-alpine` image.

```bash
docker run -i -t --name nginx-mainline -p 80:80 nginx:mainline-alpine
```

![Starting the NGINX container interactively.](https://adamtheautomator.com/wp-content/uploads/2021/07/Untitled-2021-07-19T105313.345.png)

Starting the NGINX container interactively.

4\. In a web browser, navigate to the running Docker container by going to _[http://localhost](http://localhost)_. If successful, you will see the default NGINX welcome page. Since in the previous step, you started the container mapping the external port 80 to the container’s port 80 (`-p 80:80`), NGINX should be available.

![Demonstrating the NGINX welcome page availability on the external system](https://adamtheautomator.com/wp-content/uploads/2021/07/Untitled-2021-07-19T105342.049.png)

Demonstrating the NGINX welcome page availability on the external system

5\. Finally, open your command line console again and hit the key combination of `ctrl-c` to exit the running container. You still have some work to do!

## Mapping Website Files to a Container

At this point, you can easily bring up an NGINX Docker container with the sample webpage. You now need to upload your custom website to NGINX. Since containers are immutable and will purge any changes to them when recreated, you must provide a website source outside of the [Docker](https://adamtheautomator.com/create-docker-volume/) image.

Related:[How to Create (and Manage) Docker Volumes on Windows](https://adamtheautomator.com/create-docker-volume/)

The NGINX web server running on Linux stores website files in the _/usr/share/nginx/html_ directory. Rather than upload files directly to this directory, you should map a storage location to that location so that the container will pull those files from the storage location at bootup.

On your local host operating system:

1\. First, create a directory to map to the NGINX Docker container. In this example, _C:\\Articles\\NGINX_ is used to map to _/usr/share/nginx/html._

2\. In the newly-created directory, create a file, _index.html_, that contains the following. This file will be the file that NGINX serves up when navigating to the website.

```markup
<html>
    <head></head>
    <body>
        <h1>ATA Test!</h1>
        <p>Welcome to your custom NGINX index file.</p>
    </body>
</html>
```

3\. Next, on the command line, invoke `docker run` with nearly all the same parameters as step three in the previous section. But this time, include the volume parameter, `-v` as shown below.

In the example below, the `-v` parameter is mapping the local _C:\\Articles\\NGINX_ directory to the image’s _/usr/share/nginx/html_ directory. Creating this mapping will allow you to modify the contents of the _/usr/share/nginx/html_ container directory by modifying the contents of the _C:\\Articles\\NGINX_ directory.

> _This demonstrates a Windows file location, but this command works the same on Linux. For example, `-v /usr/share/myfiles:/usr/share/nginx/html`._

```docker
docker run -i -t -v c:\Articles\NGINX:/usr/share/nginx/html --name nginx-mainline -p 80:80 nginx:mainline-alpine
```

![V parameter mapping](https://adamtheautomator.com/wp-content/uploads/2021/07/Untitled-2021-07-19T105754.515.png)

V parameter mapping

4\. Finally, open a web browser and navigate to _[http://localhost](http://localhost)_. You will see the following displayed based on the newly created _index.html_ file since it is now pulling files from the local _C:\\Articles\\NGINX_ directory.

![Demonstrating the mapped index.html file.](https://adamtheautomator.com/wp-content/uploads/2021/07/Untitled-2021-07-19T105834.869.png)

Demonstrating the mapped _index.html_ file.

## Running a PHP-FPM Application with a Docker NGINX Container

By now, you can bring up an NGINX Docker container and easily modify a website’s contents. If you need a super-basic setup, this might work. But, if you plan on running a web application on NGINX, you must do a little more work.

As an example, let’s enable the NGINX image just created to run the popular web scripting language PHP using [PHP FastCGI Process Manager (FPM)](https://www.php.net/manual/en/install.fpm.php).

For this section, several new concepts must be introduced. To easily define a set of containers and their linkages, it is best to use a [Docker Compose](https://docs.docker.com/compose/) file. Docker Compose defines the series of services and related applications in a [YAML (Yet Another Markup Language)](https://yaml.org/) file.

Related:[Everything You Need to Know about Using Docker Compose](https://adamtheautomator.com/docker-compose-tutorial/)

In addition, since you need to copy a custom configuration file for the default site, into the NGINX container, a custom version of the `nginx:mainline-alpine` image is needed. To extend an existing image, a _[dockerfile](https://docs.docker.com/engine/reference/builder/)_ is used and built with the `build` step in the Docker Compose file.

1\. Create a directory to contain your configuration files. In this example, the directory _C:\\Articles\\NGINXPHP_ is used.

2\. First, create the file, _dockerfile_, with the following contents.

```docker
# The image to pull the base configuration from
FROM nginx:mainline-alpine
# The directory where any additional files will be referenced
WORKDIR C:\Articles\NGINXPHP
# Copy the custom default.conf from the WORKDIR (.) and overwrite the existing internal configuration in the NGINX container
COPY ./default.conf /etc/nginx/conf.d/default.conf
```

3\. Next, create the file _docker-compose.yml_ file, containing the following.

```yaml
# The specification version of docker-compose
version: "3.9"
# The collection of applications composing this service
services:
  # The NGINX custom container
  web:
    # Instead of referencing image: nginx:mainline-alpine here, use build to
    # reference the current directory (.), which will look for a dockerfile
    # by default
    build: .
    # The external directory location to map to an internal location
    volumes:
      - C:\Articles\NGINXPHP:/usr/share/nginx/html
    # The external port mapping to internal port mapping
    ports:
      - "80:80"
  php:
    image: php:fpm-alpine
    # It is important that both containers can reference the same files
    volumes:
      - C:\Articles\NGINXPHP:/usr/share/nginx/html
```

4\. Finally, create the NGINX configuration file, _default.conf_, with the following.

```yaml
server {
    # The port to listen on
    listen 80;
    # The root directory, which must exactly match the internal volume share
    root /usr/share/nginx/html;

    # For all files with the PHP extension run the following
    location ~ ^/.+\.php(/|$) {
        # Pass the request to the host "php" and port 9000 (default PHP-FPM port)
        fastcgi_pass  php:9000;
	# Include the default NGINX FastCGI Parameters
        include       fastcgi_params;
	# Define one additional parameter telling PHP-FPM where to find the file
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
```

> _You may wonder where “PHP” for the hostname came from. By default, a network shared by all applications contained in the service is created using the name of the parent directory. Each container is assigned a hostname equal to the application name. In this example, the network is `nginxphp` and the hostnames are `web` and `php`._

5\. In a terminal session, navigate to your custom Docker configuration file directory, which in this example is _C:\\Articles\\NGINXPHP_. Run the command, `docker-compose up` to generate and start your custom service.

![Starting the set of containers specified in Docker Compose.](https://adamtheautomator.com/wp-content/uploads/2021/07/Untitled-2021-07-19T110226.061.png)

Starting the set of containers specified in Docker Compose.

6\. Now that the set of containers are up and running, you need a PHP file to test the configuration out. Create the file, _index.php_, in your NGINX Docker shared directory which is _C:\\Articles\\NGINXPHP_ in this tutorial.

```php
<?php phpinfo(); ?>
```

7\. Open a web browser and navigate to http://localhost/index.php to verify that the PHP file is properly shown.

![Verifying PHP file](https://adamtheautomator.com/wp-content/uploads/2021/07/Untitled-2021-07-19T110338.012.png)

Verifying PHP file

## Conclusion

Docker NGINX containers are incredibly useful for testing and development. With proper care and attention, Docker containers can help to greatly increase a production web server’s capability as well!

Now that you have successfully provisioned an NGINX container and a linked PHP-FPM container, try adding a database container into the mix for a full web application environment.

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fnginx-on-docker%2F&text=Provision%20NGINX%20on%20Docker%20and%20Increase%20Server%20Capabilities)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fnginx-on-docker%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fnginx-on-docker%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2021/07/How-to-Set-up-an-NGINX-Reverse-Proxy-in-Docker-Step-by-Step.jpg)

### [Create an NGINX Reverse Proxy in Docker and Learn 1 New Skill!](/nginx-reverse-proxy-in-docker/)

Learn how to set up an NGINX reverse proxy in Docker using PHP-FM and NodeJS in this step-by-step tutorial.

![](https://adamtheautomator.com/wp-content/uploads/2026/02/featured_image-13.webp)

### [Azure Container Apps: Instant Preview Environments per PR](/build-ephemeral-preview-environments-every-pr/)

Build isolated preview environments for every pull request using Azure Container Apps revision labels and Azure DevOps pipelines with scale-to-zero economics.

![](https://adamtheautomator.com/wp-content/uploads/2025/11/55418e927e511ae263219c072e27d637c2a967a5036de7020b329582db775c26.png)

### [Automating Docker Container Health Checks with Python and Local Notifications](/docker-health-checks-python/)

Docker's built-in health checks are passive—they tell Docker when a container fails, but do they tell you? In this tutorial, we'll build a lightweight Python monitoring system that runs entirely on your infrastructure with zero external dependencies. You'll learn to detect container failures in real-time, send instant alerts, and maintain a complete audit log of every state change.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
