Skip to content

Bad Gateway - error create table npm.migrations Permission Denied #1499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
myki57 opened this issue Oct 19, 2021 · 26 comments
Open

Bad Gateway - error create table npm.migrations Permission Denied #1499

myki57 opened this issue Oct 19, 2021 · 26 comments
Labels

Comments

@myki57
Copy link

myki57 commented Oct 19, 2021

Hi Team,
looking some help regarding NPM. Strangely I manage to make NPM work perfectly yesterday. But now that I started again my docker compose I have a strange issue.

Problem:

  • UX side : Bad gateway on the login page
  • Logs from NPM :
    ✖  error     create table `migrations` (`id` int unsigned not null auto_increment primary key, `name` varchar(255), `batch` int, `migration_time` timestamp) - ER_CANT_CREATE_TABLE: Can't create table `npm`.`migrations` (errno: 13 "Permission denied")
    
  • Logs from DB (only warnings) :
    2021-10-19 16:21:01 0 [Warning] 'user' entry '@ed85e71078a5' ignored in --skip-name-resolve mode.
    2021-10-19 16:21:01 0 [Warning] 'proxies_priv' entry '@% root@ed85e71078a5' ignored in --skip-name-resolve mode.
    2021-10-19 16:27:06 3 [Warning] Aborted connection 3 to db: 'npm' user: 'npm' host: '172.29.0.7' (Got an error reading communication packets) 
    

Sadly I didn't change anything from the initial config (except ports) :

app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      - '80:80'
      - '81:81'
      - '8091:443'
    environment:
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "npm"
      DB_MYSQL_PASSWORD: "npm"
      DB_MYSQL_NAME: "npm"
    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'
    volumes:
      - ./data/mysql:/var/lib/mysql 

Do you guys have any idea about this issue ?

@myki57
Copy link
Author

myki57 commented Oct 19, 2021

After verification 172.29.0.7 is the NPM IP address. So maybe there's a simple issue with NPM that is not connected to mariadb.

@myki57
Copy link
Author

myki57 commented Oct 19, 2021

I successfully connect from another container to mariadb (after installing mysql client) to the db IPadress (172.29.0.7) or with the internal docker name "db".

@zippyy
Copy link

zippyy commented Dec 3, 2021

i have the same issue except mine says migrations lock read only

@chaptergy
Copy link
Collaborator

@zippyy those two issues have nothing to do with each other, yours is entirely different.

But issues like these is why we now recommend using the SQLite database, which is much less error prone than having a second container for the database. If you have not set up much just use the new docke-compose.yml provided in the quick setup. If you have, and would like to migrate to SQLite, see #1529 (comment)

@dbeeren
Copy link

dbeeren commented Mar 28, 2023

In the new release there are no dependencies with a database anymore.

There are two options:

  1. Rollback to a previous version
  2. Build a new image without the "db" parameters for the my sql. (I seperate those two and the latest release worked for me).

Somehow the database is intergrated in the image. The only disadvantage is that you need to build up the url's in the proxy again.
No need for seperate mysql db anymore.

@dbeeren
Copy link

dbeeren commented Mar 28, 2023

Hi Team, looking some help regarding NPM. Strangely I manage to make NPM work perfectly yesterday. But now that I started again my docker compose I have a strange issue.

Problem:

* UX side : Bad gateway on the login page

* Logs from NPM :
  ```
  ✖  error     create table `migrations` (`id` int unsigned not null auto_increment primary key, `name` varchar(255), `batch` int, `migration_time` timestamp) - ER_CANT_CREATE_TABLE: Can't create table `npm`.`migrations` (errno: 13 "Permission denied")
  ```

* Logs from DB (only warnings) :
  ```
  2021-10-19 16:21:01 0 [Warning] 'user' entry '@ed85e71078a5' ignored in --skip-name-resolve mode.
  2021-10-19 16:21:01 0 [Warning] 'proxies_priv' entry '@% root@ed85e71078a5' ignored in --skip-name-resolve mode.
  2021-10-19 16:27:06 3 [Warning] Aborted connection 3 to db: 'npm' user: 'npm' host: '172.29.0.7' (Got an error reading communication packets) 
  ```

Sadly I didn't change anything from the initial config (except ports) :

app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      - '80:80'
      - '81:81'
      - '8091:443'
    environment:
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "npm"
      DB_MYSQL_PASSWORD: "npm"
      DB_MYSQL_NAME: "npm"
    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'
    volumes:
      - ./data/mysql:/var/lib/mysql 

Do you guys have any idea about this issue ?

There are two options:

Rollback to a previous version
Build a new image without the "db" parameters for the my sql. (I seperate those two and the latest release worked for me).

Somehow the database is intergrated in the image. The only disadvantage is that you need to build up the url's in the proxy again.
No need for seperate mysql db anymore.

@PowerUser64
Copy link

I get the same error on the latest build. I switched to the github-pr-2659 release (from around a month ago) and the backend works now. I can't log in to the management panel, but at least all the proxies work! 🎉

Here's the error that's getting spammed in my log:

nginx-proxy-manager     | [4/1/2023] [9:53:32 AM] [Global   ] › ✖  error     create table `migrations` (`id` int unsigned not null auto_increment primary key, `name` varchar(255), `batch` int, `migration_time` timestamp) - ER_CANT_CREATE_TABLE: Can't create table `npm`.`migrations` (errno: 13 "Permission denied")

@jornl
Copy link

jornl commented Apr 1, 2023

I got it working. Had to access the db-container and change the owner of the folder /var/lib/mysql/npm.

docker exec -it proxydatabase /bin/sh
cd /var/lib/mysql
chown -R mysql:mysql npm
exit

@domidetres
Copy link

hey @jornl i also got it working like that, but that would suggest that on every update of the db-container this configuration needs be done - right? - any fix on that?

@ggriffinorg
Copy link

ggriffinorg commented Apr 3, 2023

Hi,

If you are updating from 2.9.22 and using a Docker Compose file, the Persistent Volume for the MariaDB Aria Container must not be the same as the Persistent Volume for the NPM Container.

So you if you have a "mysql" folder in ./data folder from NPM, create a new Persistent Volume for MariaDB Aria Container, copy the "mysql" folder into it. Then recreate both containers with "latest" and you'll have no issues.

In Docker Compose it would look like this:

NPM Container

    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/docker/nginx-proxy-manager/data:/data
      - /var/docker/nginx-proxy-manager/letsencrypt:/etc/letsencrypt

MariaDB Aria Containter

    volumes:
#      - /var/docker/nginx-proxy-manager/data/mysql:/var/lib/mysql # OLD PATH THAT CAUSES ISSUES
      - /var/docker/mariadb-aria/data/mysql:/var/lib/mysql

Trust me it works.

Please check here:

https://nginxproxymanager.com/setup/#using-mysql-mariadb-database

BR,
Greg

@jornl
Copy link

jornl commented Apr 4, 2023

@domidetres you're correct about having to change this every time. A permanent solution would be what @ggriffinorg posted.

@pthoelken
Copy link

If you don't want to rebuild the database image with new entrypoints you can start the docker environment with a start script like this:

#!/bin/bash -e
docker-compose pull
docker-compose up -d
sleep 5
docker exec -it <containername> chown -R mysql:mysql /var/lib/mysql/nginxproxymanager

exit 0

Save this as startup.sh in your docker-compose.yml file location and make it executable with chmod +x startup.sh. This will start up the containers and change the permissions from the database folder into the database container to the right one.

Maybe you have to adjust the path "/var/lib/mysql/nginxproxymanager" to your specific (from your docker-compose.yml) file.

In my case I took the startup.sh file to my crontab file as @reboot.

@neil-west-oz
Copy link

Hi,

If you are updating from 2.9.22 and using a Docker Compose file, the Persistent Volume for the MariaDB Aria Container must not be the same as the Persistent Volume for the NPM Container.

So you if you have a "mysql" folder in ./data folder from NPM, create a new Persistent Volume for MariaDB Aria Container, copy the "mysql" folder into it. Then recreate both containers with "latest" and you'll have no issues.

In Docker Compose it would look like this:

NPM Container

    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/docker/nginx-proxy-manager/data:/data
      - /var/docker/nginx-proxy-manager/letsencrypt:/etc/letsencrypt

MariaDB Aria Containter

    volumes:
#      - /var/docker/nginx-proxy-manager/data/mysql:/var/lib/mysql # OLD PATH THAT CAUSES ISSUES
      - /var/docker/mariadb-aria/data/mysql:/var/lib/mysql

Trust me it works.

Please check here:

https://nginxproxymanager.com/setup/#using-mysql-mariadb-database

BR, Greg

Many thanks for this solution - it was starting to do my head in!

@ajeffco
Copy link

ajeffco commented May 13, 2023

Hi,

If you are updating from 2.9.22 and using a Docker Compose file, the Persistent Volume for the MariaDB Aria Container must not be the same as the Persistent Volume for the NPM Container.

So you if you have a "mysql" folder in ./data folder from NPM, create a new Persistent Volume for MariaDB Aria Container, copy the "mysql" folder into it. Then recreate both containers with "latest" and you'll have no issues.

In Docker Compose it would look like this:

NPM Container

    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/docker/nginx-proxy-manager/data:/data
      - /var/docker/nginx-proxy-manager/letsencrypt:/etc/letsencrypt

MariaDB Aria Containter

    volumes:
#      - /var/docker/nginx-proxy-manager/data/mysql:/var/lib/mysql # OLD PATH THAT CAUSES ISSUES
      - /var/docker/mariadb-aria/data/mysql:/var/lib/mysql

Trust me it works.

Please check here:

https://nginxproxymanager.com/setup/#using-mysql-mariadb-database

BR, Greg

Thank you for this. Was driving me nuts, and tripped over it quite by accident.

@JoelFrojmowicz
Copy link

Hi,

If you are updating from 2.9.22 and using a Docker Compose file, the Persistent Volume for the MariaDB Aria Container must not be the same as the Persistent Volume for the NPM Container.

So you if you have a "mysql" folder in ./data folder from NPM, create a new Persistent Volume for MariaDB Aria Container, copy the "mysql" folder into it. Then recreate both containers with "latest" and you'll have no issues.

In Docker Compose it would look like this:

NPM Container

    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/docker/nginx-proxy-manager/data:/data
      - /var/docker/nginx-proxy-manager/letsencrypt:/etc/letsencrypt

MariaDB Aria Containter

    volumes:
#      - /var/docker/nginx-proxy-manager/data/mysql:/var/lib/mysql # OLD PATH THAT CAUSES ISSUES
      - /var/docker/mariadb-aria/data/mysql:/var/lib/mysql

Trust me it works.

Please check here:

https://nginxproxymanager.com/setup/#using-mysql-mariadb-database

BR, Greg

After 3 hours of trying to figure out what happened to my NPM instance, I just got to your post and magically everything is running normally.
I cannot thank you enough for this solution!

THANKS !!!!!

@baddate
Copy link

baddate commented Jul 27, 2023

Hi,

If you are updating from 2.9.22 and using a Docker Compose file, the Persistent Volume for the MariaDB Aria Container must not be the same as the Persistent Volume for the NPM Container.

So you if you have a "mysql" folder in ./data folder from NPM, create a new Persistent Volume for MariaDB Aria Container, copy the "mysql" folder into it. Then recreate both containers with "latest" and you'll have no issues.

In Docker Compose it would look like this:

NPM Container

    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/docker/nginx-proxy-manager/data:/data
      - /var/docker/nginx-proxy-manager/letsencrypt:/etc/letsencrypt

MariaDB Aria Containter

    volumes:
#      - /var/docker/nginx-proxy-manager/data/mysql:/var/lib/mysql # OLD PATH THAT CAUSES ISSUES
      - /var/docker/mariadb-aria/data/mysql:/var/lib/mysql

Trust me it works.

Please check here:

nginxproxymanager.com/setup/#using-mysql-mariadb-database

BR, Greg

it works when upgrading from 2.9.19 to 2.10.3.

@msawyer91
Copy link

I got it working. Had to access the db-container and change the owner of the folder /var/lib/mysql/npm.

docker exec -it proxydatabase /bin/sh
cd /var/lib/mysql
chown -R mysql:mysql npm
exit

Thank you! Running the above commands (my container name is different) worked perfectly and immediately NPM started working. The issue was that I have Watchtower running in another container and it alerted me that mariadb had a newer version. I ran docker-compose pull to upgrade, and that caused the problem. Thankfully the above bash script fixed it.

Matt

@samuellhwarren
Copy link

I got it working. Had to access the db-container and change the owner of the folder /var/lib/mysql/npm.

docker exec -it proxydatabase /bin/sh
cd /var/lib/mysql
chown -R mysql:mysql npm
exit

Thank you! Running the above commands (my container name is different) worked perfectly and immediately NPM started working. The issue was that I have Watchtower running in another container and it alerted me that mariadb had a newer version. I ran docker-compose pull to upgrade, and that caused the problem. Thankfully the above bash script fixed it.

Matt

That worked for me!

@tanushshukla
Copy link

I got it working. Had to access the db-container and change the owner of the folder /var/lib/mysql/npm.

docker exec -it proxydatabase /bin/sh
cd /var/lib/mysql
chown -R mysql:mysql npm
exit

This worked for me, too! Thanks!

@ektorasdj
Copy link

Hello everyone, what about users with database.sqlite? Nothing works for that to my configuration.

Thank you

@pnpninja
Copy link

pnpninja commented Jan 20, 2024

I got the same issue when trying to access NGINX Proxy Manager

Here is my Docker Compose File

version: "3"
volumes:
  nextcloud-data:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /portainer/nextcloud/data
  mysql-db:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /portainer/mysql
  npm-data:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /portainer/npm-data
  npm-ssl:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /portainer/npm-ssl
  npm-db:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /portainer/npm-db

networks:
  frontend:
    # add this if the network is already existing!
    # external: true
  backend:

services:
  nextcloud-app:
    image: nextcloud
    restart: always
    volumes:
      - nextcloud-data:/var/www/html
    environment:
      - MYSQL_PASSWORD=<redacted>
      - MYSQL_DATABASE=common
      - MYSQL_USER=prateek-nextcloud
      - MYSQL_HOST=mysql-db
    networks:
      - frontend
      - backend

  mysql-db:
    image: mysql
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - mysql-db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=<redacted>
      - MYSQL_PASSWORD=<redacted>
      - MYSQL_DATABASE=common
      - MYSQL_USER=prateek-nextcloud
    networks:
      - backend

  npm-app:
    image: jc21/nginx-proxy-manager:latest
    restart: always
    ports:
      - "80:80"
      - "81:81"
      - "443:443"
    environment:
      - DB_MYSQL_HOST=npm-db
      - DB_MYSQL_PORT=3306
      - DB_MYSQL_USER=npm
      - DB_MYSQL_PASSWORD=<redacted>
      - DB_MYSQL_NAME=npm
    volumes:
      - npm-data:/data
      - npm-ssl:/etc/letsencrypt
    networks:
      - frontend
      - backend

  npm-db:
    image: jc21/mariadb-aria:latest
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=<redacted>
      - MYSQL_DATABASE=npm
      - MYSQL_USER=npm
      - MYSQL_PASSWORD=<redacted>
    volumes:
      - npm-db:/var/lib/mysql
    networks:
      - backend

How do I fix it?

I tried the command -

  docker exec -it <container ID of npm-db> /bin/sh
  cd /var/lib/mysql
 chown -R mysql:mysql npm
 exit

@firefox7518
Copy link

Hi all
I have a standalone mariadb server where I host the data of NPM. I DO NOT WANT to migrate to SQLITE as I have hundreds of DBs already on the standalone server and I don't want to manage multiple DB systems. So the solution above setting the folders right or using chown etc. does obviously not work as it is not in a container nor do I start a db container.

So how can I fix this now and get rid of the "Bad Gateway" message when trying to login?

@samuellhwarren
Copy link

samuellhwarren commented Mar 22, 2024 via email

@cmcconomy
Copy link

I was able to fix this with the following docker compose:

version: '3.8'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    environment:
      PUID: 1000
      PGID: 1000
      DB_SQLITE_FILE: "/data/sqlite/database.sqlite"    
    restart: unless-stopped
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - nginx-mgr-sqlite:/data/sqlite
      - /mnt/prox-share/docker/nginx-proxy-manager/data:/data
      - /mnt/prox-share/docker/nginx-proxy-manager/letsencrypt:/etc/letsencrypt

volumes:
    nginx-mgr-sqlite:
        external: false

@simonhoellein
Copy link

I also facing the same issue with my instance. A quick fix is to restart the MariaDB docker container:

docker restart <container-id-db>

This at least helps to clear the error and you can login to the webinterface again. Not a permanent solution but mabe helps if you are in a hurry ;)

Copy link

Issue is now considered stale. If you want to keep it open, please comment 👍

@github-actions github-actions bot added the stale label Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests