How to Install Nginx Proxy Manager on Docker with Docker Compose
Nginx Proxy Manager (NPM) is a powerful and easy-to-use web server and reverse proxy management tool. It simplifies the process of managing multiple websites and services, offering a graphical user interface to handle SSL certificates, domain routing, and other related tasks. If you are looking to manage your web services efficiently, installing Nginx Proxy Manager using Docker and Docker Compose is an excellent choice.
In this guide, we will walk you through the entire process, from setting up Docker and Docker Compose to deploying Nginx Proxy Manager on your server. By the end of this article, you should be able to run Nginx Proxy Manager smoothly and securely.
Prerequisites
Before we begin, ensure you have the following:
- A server or machine running Linux (Ubuntu/Debian) or Windows: This guide focuses on Linux, but the steps for Windows are similar.
- Basic knowledge of the command line: You should be comfortable using terminal commands.
- Docker and Docker Compose installed.
Step 1: Set Up a Directory for Nginx Proxy Manager
Create a directory where your Docker Compose configuration files will reside. This will help keep everything organized.
mkdir ~/nginx-proxy-manager
cd ~/nginx-proxy-manager
Step 2: Create the Docker Compose File
In the newly created directory, create a docker-compose.yml
file using a text editor such as vim
:
vi docker-compose.yml
In the file, paste the following configuration:
version: '3'
services:
app:
container_name: nginx-pm
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
- '80:80'
- '81:81'
- '443:443'
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
networks:
default:
name: monitoring-net
external: true
Since Docker Compose version 2.0, released in October 2021, it’s no longer mandatory to specify a Docker Compose file version. If no version is indicated, Docker automatically assumes the latest supported version.
However, specifying the version in the docker-compose.yml file can be useful for ensuring compatibility with older configurations or for specifying a particular version you want to use. In many cases though, if you don’t need to specify the version, you can omit this line.
Explanation of Key Components
- Container Name (
container_name: nginx-pm
):- This line specifies the name of the container that Docker will use. It’s useful for easily identifying and managing containers, especially when you have multiple containers running.
- Custom Network (
networks: monitoring-net
):- The
networks
section at the bottom defines a network configuration for Docker Compose. By settingexternal: true
, you’re telling Docker Compose to use an existing network calledmonitoring-net
. This is beneficial when you want multiple services to communicate over a shared network, particularly in more complex setups where containers need to interact with other services not defined in the same Docker Compose file.
- The
- Other Elements:
- The
image
directive specifies the Docker image to use, which isjc21/nginx-proxy-manager:latest
. - The
ports
directive maps the container’s internal ports to the host machine’s ports, allowing external access. - The
volumes
directive mounts host directories to the container, storing persistent data such as configurations and SSL certificates.
- The
Ensure the Network Exists:
- Since you’re using an external network (
monitoring-net
), ensure that it exists:
docker network create monitoring-net
If the network already exists, you can skip this step.
Start the Containers:
- Run the following command to start the Nginx Proxy Manager:
docker-compose up -d
- Access the Interface:
- Once the containers are running, access the Nginx Proxy Manager by navigating to
http://<your-server-ip>:81
in a web browser.
- Once the containers are running, access the Nginx Proxy Manager by navigating to
Conclusion
Installing Nginx Proxy Manager on Docker with Docker Compose provides a robust and user-friendly solution for managing web services. With SSL management, domain routing, and an easy-to-navigate interface, Nginx Proxy Manager simplifies tasks that would otherwise require in-depth configuration.
By following this guide, you now have a fully operational Nginx Proxy Manager setup on your server, ready to handle your web traffic efficiently and securely.
Thank you for reading the article! If you found the information useful, you can donate using the buttons below:
Donate ☕️ with PayPalDonate 💳 with Revolut