Install jc21 Nginx Proxy Manager w/ Docker Compose/MariaDB Aria Container

Posted March 5, 2024
Install jc21 Nginx Proxy Manager w/ Docker Compose|MariaDB Aria Container

This guide teaches how to install, set up, and run Nginx Proxy Manager with Docker and Docker Compose. You will alongside use the latest jc21/nginx-proxy-manager to Deploy Nginx Proxy Manager and use the latest jc21/mariadb-aria and your Nginx proxy Database Manager.

You’ll learn:

  • How to Install Docker and Docker Compose to run jc21/Nginx Proxy Manager and MariaDB Aria.
  • Installing and setting up a MariaDB Container using Docker Compose.
  • Running Docker Compose (docker-compose.yml) to deploy Nginx Proxy Manager.
  • Configuring Nginx Proxy Manager.
  • How to use the Deployed Nginx Proxy Manager to manage Proxy Hosts and SSL Certificates.
  • Obtaining and installing SSL certificates for secure web app connections.
  • Configuring Nginx Proxy Manager SSL termination and HTTPS redirection.

Ready? Dive in now and Install Nginx Proxy Manager with Docker Compose Container and jc21 MariaDB Aria like a Pro.

Related: How to Install and Run Nginx Proxy Manager with Kubernetes

Prerequisites to Install Nginx Proxy Manager with Docker and Docker Compose

Before running your proxy manager:

  • You must have Docker i nstalled and running on your computer.
  • You will need a self-hosted web app. I will use Portainer which runs with Docker.
  • To manage HTTPS and SSL Certificates, ensure you have a working domain name and it can accept DNS configurations with subdomains

Note: If you don’t have Docker and Docker compose, check the next step to set it up with a few commands:

Installing Docker and Docker Compose for Nginx Proxy Manager

If you are using Windows, check the Docker doc and install Docker Desktop on the Windows machine. Then ensure Docker is up and running:

Installing Docker and Docker Compose for Nginx Proxy Manager

I will use Linux (Ubuntu) to get Docker running as follows:

  • Update Ubuntu package index:
sudo apt update
sudo apt upgrade -y
  • Ensure you don’t have conflicting previously installed Docker settings:
sudo apt-get remove docker docker-engine docker.io containerd runc
# Expected Output: Unable to locate package docker-engine
  • Add Docker dependent packages:
sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common -y
  • Create Docker installation GPG Key:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
  • Use apt to add a Docker repository to package sources:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  • Install Docker Engine and Docker Compose
## Update the new packages first
sudo apt update

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
  • Check versions to ensure Docker Compose and Docker are available:
### For Docker
sudo docker --version
## Check the available Docker Compose version
docker compose version

Installing Docker and Docker Compose for Nginx Proxy Manager

  • Finally, ensure Docker is ready and running:

Installing Docker and Docker Compose for Nginx Proxy Manager

Installing jc21 Nginx Proxy Manager Docker Compose with YML

With Docker up and running, you can now use any Docker and Docker compose to set up your Nginx Proxy Manager. Here, I recommend you Create a new directory that you will use to save the Nginx Proxy Manager Docker Compose YML file:

mkdir nginx-proxy-manager

CD to this new directory:

cd nginx-proxy-manager

Within nginx-proxy-manager, create a Docker Compose YML (docker-compose.yml):

nano docker-compose.yml

This will get the latest Nginx Proxy Manager based on the jc21 image as follows:

version: '3.9'

services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'  # Docker image for Nginx Proxy Manager
    ports:
      - '80:80' 
      # container port 81
      # for Nginx Proxy Manager dashboard
      - '81:81'  
      - '443:443' 
    environment:
      DB_MYSQL_HOST: "mariadb"  # MariaDB
      DB_MYSQL_PORT: 3306  
      DB_MYSQL_USER: "proxy_manager_user"  # database Username 
      DB_MYSQL_PASSWORD: "user_pass"  # Password 
      DB_MYSQL_NAME: "proxy-manager"  # MariaDB database
    volumes:
      - ./data:/data  
      # Map host directory ./letsencrypt to container directory /etc/letsencrypt
      - ./letsencrypt:/etc/letsencrypt  

In this case:

  • image: ‘jc21/nginx-proxy-manager:latest’ is the Proxy Manager Docker Image that Docker Compose will use.
  • Maps ports on the host machine to ports within the container. Port 80 of the host is mapped to port 80 of the container to allow HTTP traffic to reach the Nginx Proxy Manager.
  • Volumes persist data between container restarts. ./data:/data for Nginx Proxy Manager data and ./letsencrypt:/etc/letsencrypt for Nginx Let’s Encrypt SSL certificates.
  • Environment variables must be used to configure the Nginx Proxy Manager. They connect configuring the Nginx Proxy Manager to MariaDB.
  • This Proxy manager will use MariaDB as the host. Check the following steps to get MariaDB ready.

Setting Up a jc21 MariaDB Aria Docker Compose Container

Nginx Proxy Manager will need to store configuration settings, user data, logs, or other information in a database. This is where MariaDB comes in to save this data.

MariaDB container will be the Manager data persistence lifecycle as d dedicated database backend. Go ahead and use jc21/MariaDB aria within Docker compose as follows:

At this point, your complete docker-compose.yml should look as follows

version: '3.9'
services:
  # Nginx Proxy Manager Service
  app:
    restart: always
    image: 'jc21/nginx-proxy-manager:latest'
    ports:
      - '80:80'
      # Port to access Nginx Proxy Manager 
      - '81:81'
      # Host port: Container port for SSL
      - '443:443'
    environment:
      # MariaDB host
      - DB_MYSQL_HOST=mariadb
      # MariaDB port
      - DB_MYSQL_PORT=3306
      # MariaDB username 
      - DB_MYSQL_USER=proxy_manager_user
      # user password
      - DB_MYSQL_PASSWORD=user_pass
      # Nginx Proxy Manager database name 
      - DB_MYSQL_NAME=proxy-manager
      - DISABLE_IPV6=true
    networks:
    # Connect to nginx-proxy-manager-nw and reverseproxy-nw networks
      - nginx-proxy-manager-nw
      - reverseproxy-nw
    volumes:
     # Mounting  Nginx Proxy Manager data
      - /mnt/containers/nginx-proxy-manager/container-data/data:/data:Z
    # directory for SSL certificates
      - /mnt/containers/nginx-proxy-manager/container-data/letsencrypt:/etc/letsencrypt:Z
     
  # MariaDB Service
  mariadb:
    restart: always
    image: 'jc21/mariadb-aria:latest'
    environment:
      # Root password
      - MYSQL_ROOT_PASSWORD=root_pass
      # Database name
      - MYSQL_DATABASE=proxy-manager
      # MariaDB username
      - MYSQL_USER=proxy_manager_user
      # user password 
      - MYSQL_PASSWORD=user_pass
    volumes:
      - /mnt/containers/nginx-proxy-manager/container-data/mysql:/var/lib/mysql:Z
      # Connect to nginx-proxy-manager-nw network
    networks:
      - nginx-proxy-manager-nw

networks:
  nginx-proxy-manager-nw: # Create the nginx-proxy-manager-nw network
  reverseproxy-nw: #  Add reverseproxy-nw network
  # Use external network
    external: true 

Running Docker Compose to deploy Nginx Proxy Manager

Docker Compose uses the docker compose up command to run any container. You need to ensure the external network reverseproxy-nw exists before you try to use it in your Docker Compose configuration. Use the docker network create command as follows:

sudo docker network create reverseproxy-nw

Next, ensure you in the nginx-proxy-manager directory containing docker-compose.yml and run the following command:

docker compose up -d

Running Docker Compose to deploy Nginx Proxy Manager

Now, confirm if MariaDB and Nginx Proxy Manager containers are running:

Running Docker Compose to deploy Nginx Proxy Manager

Running Docker Compose to deploy Nginx Proxy Manager

Accessing and Configuring Nginx Proxy Manager

You now need to open http://your_server_ip:81 on the browser to access the Deployed Nginx Proxy Manager as follows:

Accessing and Configuring Nginx Proxy Manager

Use Default Administrator User to Log in:

# Username
[email protected] 
# The password
changeme

Next, Change your username and password to your liking and modify with your details.

Accessing and Configuring Nginx Proxy Manager

And now you have the first view of the newly installed Nginx Proxy Manager:

Accessing and Configuring Nginx Proxy Manager

If you have access to the /data folder of the container, you will have the Nginx Proxy Manager data as follows:

Accessing and Configuring Nginx Proxy Manager

How to Add New Proxy Domain to Nginx Proxy Manager

Your Nginx Proxy Manager is ready with Docker and Docker Compose. It’s time to add and manage Proxy Hosts.

Navigate to Hosts and Access your Proxy Hosts. Here, Add Proxy Host. Below is an example of Adding a Portainer Container and Accessing a subdomain:

How to Add New Proxy Domain to Nginx Proxy Manager

At the same Navigate to the SSL section. Here you need to add your HTTPS and lets encrypt SSL certificates to your server as follows:

How to Add New Proxy Domain to Nginx Proxy Manager

You added a New Proxy that should be available on your Nginx Proxy Manager:

How to Add New Proxy Domain to Nginx Proxy Manager

Go deeper and find more futures of this Manager and add them based on your Proxy goals.

Check this Run Portainer Behind Nginx Reverse Proxy Manager and HTTPS guide to understand more details on how to use your Dockerized Nginx Proxy Manager

Conclusion

You have now learned:

  • How to Install Docker and Docker Compose to run jc21/Nginx Proxy Manager and MariaDB Aria.
  • Installing and setting up a MariaDB Container using Docker Compose.
  • Running Docker Compose (docker-compose.yml) to deploy Nginx Proxy Manager.
  • Configuring Nginx Proxy Manager.
  • How to use the Deployed Nginx Proxy Manager to manage Proxy Hosts and SSL Certificates.
Install jc21 Nginx Proxy Manager w/ Docker Compose/MariaDB Aria Container

Written By:

Joseph Chege