nginx-proxy-manager: Bad Gateway - error create table npm.migrations Permission Denied

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 ?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 23

Most upvoted comments

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

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

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.

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.

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

@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 https://github.com/jc21/nginx-proxy-manager/discussions/1529#migrate-mariadb-to-sqlite-dbeaver