Skip to content

Standardize environment variables for database connection #4677

@EdwinBetanc0urt

Description

@EdwinBetanc0urt

Is your feature request related to a problem? Please describe.

Currently, there are multiple environment variables for each type of database connection. So if several environment variables are passed, for example from Postgres and MySQL/MariaDB, which one will actually be used as the connection?

Describe the solution you'd like

This should be easier when specifying the database engine, configuring fewer environment variables, and knowing where they will be set based on the DB_ENGINE environment variable.

Replace the environment variables and unify them as follows:

  • DB_MYSQL_HOST and DB_POSTGRES_HOST, with DB_HOST.
  • DB_MYSQL_PORT and DB_POSTGRES_PORT, with DB_HOST.
  • DB_MYSQL_USER and DB_POSTGRES_USER with DB_USER.
  • DB_MYSQL_PASSWORD and DB_POSTGRES_PASSWORD with DB_PASSWORD.
  • DB_MYSQL_NAME and DB_POSTGRES_NAME with DB_NAME.

Describe alternatives you've considered

MySQL/MariaDB stack:

services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      # These ports are in format <host-port>:<container-port>
      - '80:80' # Public HTTP Port
      - '443:443' # Public HTTPS Port
      - '81:81' # Admin Web Port
      # Add any other Stream port you want to expose
      # - '21:21' # FTP
    environment:
      # MySQL/MariaDB connection parameters:
      DB_ENGINE: 'mysql'
      DB_HOST: "db"
      DB_PORT: 3306
      DB_NAME: "npm"
      DB_USER: "npm"
      DB_PASSWORD: "npm"
      # Uncomment this if IPv6 is not enabled on your host
      # DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db

  db:
    image: 'jc21/mariadb-aria:latest'
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'npm'
      MARIADB_AUTO_UPGRADE: '1'
    volumes:
      - ./mysql:/var/lib/mysql

Postgres stack:

services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      # These ports are in format <host-port>:<container-port>
      - '80:80' # Public HTTP Port
      - '443:443' # Public HTTPS Port
      - '81:81' # Admin Web Port
      # Add any other Stream port you want to expose
      # - '21:21' # FTP
    environment:
      # PostgreSQL parameters:
      DB_ENGINE: 'postgres'
      DB_HOST: 'db'
      DB_PORT: '5432'
      DB_NAME: 'npm'
      DB_USER: 'npm'
      DB_PASSWORD: 'npmpass'
      # Uncomment this if IPv6 is not enabled on your host
      # DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db

  db:
    image: postgres:latest
    environment:
      POSTGRES_USER: 'npm'
      POSTGRES_PASSWORD: 'npmpass'
      POSTGRES_DB: 'npm'
    volumes:
      - ./postgres:/var/lib/postgresql/data

Additional context
The same could work for other SQL databases such as Firebird, Microsoft SQL Server, Oracle, or Amazon Relational Database Service.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions