[GH-ISSUE #198] Cannot connect to the DB when it is on another host. #172

Closed
opened 2026-02-26 06:31:08 +03:00 by kerem · 5 comments
Owner

Originally created by @chopfitzroy on GitHub (Sep 5, 2019).
Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/198

Checklist
Yes I am using the latest version.

Describe the bug
The database connection is refused when the containers are separate.

To Reproduce
I need to run the app on a docker macvlan so I have adjusted the example to be like so:

version: "3"
services:
  app:
    image: jc21/nginx-proxy-manager:latest
    restart: always
    networks:
      br0:
        ipv4_address: 192.168.1.253
    ports:
      - 80:80
      - 81:81
      - 443:443
    volumes:
      - ./config.json:/app/config/production.json
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db
    #environment:
    # if you want pretty colors in your docker logs:
    #- FORCE_COLOR=1
  db:
    #image: mariadb:latest
    build: .
    restart: always
    networks:
      br0:
        ipv4_address: 192.168.1.252
    environment:
      MYSQL_ROOT_PASSWORD: "root"
      MYSQL_DATABASE: "npm"
      MYSQL_USER: "npm"
      MYSQL_PASSWORD: "password"
    volumes:
      - ./data/mysql:/var/lib/mysql

networks:  br0:
    external: true

This is the Dockerfile I am using for the DB:

FROM mariadb:latest

LABEL maintainer="user@email.com"

RUN apt-get update && apt-get upgrade -y

# UPDATE BIND ADDRESS TO ALLOW REMOTE ACCESS (USE A FIREWALL TO MANAGE TRAFFIC)
RUN sed -Ei 's/#bind-address\s+=\s+127.0.0.1/bind-address=0.0.0.0/g' /etc/mysql/my.cnf

EXPOSE 3306

And here is my config.json:

{
  "database": {
    "engine": "mysql",
    "host": "192.168.1.252", // db when using networks (below)
    "name": "npm",
    "user": "npm",
    "password": "password",
    "port": 3306
  }
}

I also tried putting the both containers on a local bridge network and then connecting to the DB like usual (without adjusting the bind-address) same issue.

Expected behavior
I am confident that at least one of these methods should have allowed a remote connection, I based this directly on the MariaDB docs https://mariadb.com/kb/en/library/configuring-mariadb-for-remote-client-access/

Operating System

  • Unraid 6.6.7

Additional context
I can't think of anything else, but let me know if you can think of anything.

docker-compose version 1.23.2, build 1110ad01
Originally created by @chopfitzroy on GitHub (Sep 5, 2019). Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/198 **Checklist** Yes I am using the latest version. **Describe the bug** The database connection is refused when the containers are separate. **To Reproduce** I need to run the app on a docker `macvlan` so I have adjusted the example to be like so: ``` version: "3" services: app: image: jc21/nginx-proxy-manager:latest restart: always networks: br0: ipv4_address: 192.168.1.253 ports: - 80:80 - 81:81 - 443:443 volumes: - ./config.json:/app/config/production.json - ./data:/data - ./letsencrypt:/etc/letsencrypt depends_on: - db #environment: # if you want pretty colors in your docker logs: #- FORCE_COLOR=1 db: #image: mariadb:latest build: . restart: always networks: br0: ipv4_address: 192.168.1.252 environment: MYSQL_ROOT_PASSWORD: "root" MYSQL_DATABASE: "npm" MYSQL_USER: "npm" MYSQL_PASSWORD: "password" volumes: - ./data/mysql:/var/lib/mysql networks: br0: external: true ``` This is the Dockerfile I am using for the DB: ``` FROM mariadb:latest LABEL maintainer="user@email.com" RUN apt-get update && apt-get upgrade -y # UPDATE BIND ADDRESS TO ALLOW REMOTE ACCESS (USE A FIREWALL TO MANAGE TRAFFIC) RUN sed -Ei 's/#bind-address\s+=\s+127.0.0.1/bind-address=0.0.0.0/g' /etc/mysql/my.cnf EXPOSE 3306 ``` And here is my `config.json`: ```json { "database": { "engine": "mysql", "host": "192.168.1.252", // db when using networks (below) "name": "npm", "user": "npm", "password": "password", "port": 3306 } } ``` I also tried putting the both containers on a `local` bridge network and then connecting to the DB like usual (without adjusting the `bind-address`) same issue. **Expected behavior** I am confident that at least one of these methods should have allowed a remote connection, I based this directly on the MariaDB docs https://mariadb.com/kb/en/library/configuring-mariadb-for-remote-client-access/ **Operating System** - Unraid 6.6.7 **Additional context** I can't think of anything else, but let me know if you can think of anything. ``` docker-compose version 1.23.2, build 1110ad01 ```
kerem 2026-02-26 06:31:08 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@chopfitzroy commented on GitHub (Sep 6, 2019):

Okay, as it turns out I wasn't waiting long enough for the database server to start, on a positive note if anyone needs to access MariaDB remotely like me the attached Dockerfile works :).

<!-- gh-comment-id:528790400 --> @chopfitzroy commented on GitHub (Sep 6, 2019): Okay, as it turns out I wasn't waiting long enough for the database server to start, on a positive note if anyone needs to access MariaDB remotely like me the attached Dockerfile works :).
Author
Owner

@LeehamElectronics commented on GitHub (Oct 31, 2021):

Okay, as it turns out I wasn't waiting long enough for the database server to start, on a positive note if anyone needs to access MariaDB remotely like me the attached Dockerfile works :).

Which attached Docker file? The Docker file in your comment has a lot of invalid syntaxes.

<!-- gh-comment-id:955617385 --> @LeehamElectronics commented on GitHub (Oct 31, 2021): > Okay, as it turns out I wasn't waiting long enough for the database server to start, on a positive note if anyone needs to access MariaDB remotely like me the attached Dockerfile works :). Which attached Docker file? The Docker file in your comment has a lot of invalid syntaxes.
Author
Owner

@chaptergy commented on GitHub (Oct 31, 2021):

@LeehamElectronics If you want to access the MariaDB have a look at https://github.com/jc21/nginx-proxy-manager/discussions/1529#connect-to-mariadb-dbeaver, that will probably help you.

<!-- gh-comment-id:955730267 --> @chaptergy commented on GitHub (Oct 31, 2021): @LeehamElectronics If you want to access the MariaDB have a look at https://github.com/jc21/nginx-proxy-manager/discussions/1529#connect-to-mariadb-dbeaver, that will probably help you.
Author
Owner

@LeehamElectronics commented on GitHub (Oct 31, 2021):

@LeehamElectronics If you want to access the MariaDB have a look at https://github.com/jc21/nginx-proxy-manager/discussions/1529#connect-to-mariadb-dbeaver, that will probably help you.

Thanks foe the clarification, how were you able to access the NPM mariaDB remotely? I have tried exposing ports to it in my docker compose file but the port doesn't show as open. Here is my docker compose file:

services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    environment:
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "npm"
      DB_MYSQL_PASSWORD: "passss"
      DB_MYSQL_NAME: "npm"
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    restart: always
  db:
    image: 'jc21/mariadb-aria:latest'
    ports:
      - '400:3306'
    environment:
      MYSQL_ROOT_PASSWORD: 'passss'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'passss'
    volumes:
      - ./data/mysql:/var/lib/mysql
    restart: always
<!-- gh-comment-id:955800690 --> @LeehamElectronics commented on GitHub (Oct 31, 2021): > @LeehamElectronics If you want to access the MariaDB have a look at https://github.com/jc21/nginx-proxy-manager/discussions/1529#connect-to-mariadb-dbeaver, that will probably help you. Thanks foe the clarification, how were you able to access the NPM mariaDB remotely? I have tried exposing ports to it in my docker compose file but the port doesn't show as open. Here is my docker compose file: ```version: '3' services: app: image: 'jc21/nginx-proxy-manager:latest' ports: - '80:80' - '81:81' - '443:443' environment: DB_MYSQL_HOST: "db" DB_MYSQL_PORT: 3306 DB_MYSQL_USER: "npm" DB_MYSQL_PASSWORD: "passss" DB_MYSQL_NAME: "npm" volumes: - ./data:/data - ./letsencrypt:/etc/letsencrypt restart: always db: image: 'jc21/mariadb-aria:latest' ports: - '400:3306' environment: MYSQL_ROOT_PASSWORD: 'passss' MYSQL_DATABASE: 'npm' MYSQL_USER: 'npm' MYSQL_PASSWORD: 'passss' volumes: - ./data/mysql:/var/lib/mysql restart: always ```
Author
Owner

@chaptergy commented on GitHub (Oct 31, 2021):

@LeehamElectronics That's exactly how it should work. What database tool are you using? And you can't connect using port 400?

<!-- gh-comment-id:955802004 --> @chaptergy commented on GitHub (Oct 31, 2021): @LeehamElectronics That's exactly how it should work. What database tool are you using? And you can't connect using port 400?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-proxy-manager-NginxProxyManager#172
No description provided.