jgeusebroek / docker-spotweb

A docker image running ubuntu/20.04 Linux and Spotweb
47 stars 27 forks source link

Unable to connect to database #35

Closed mcwieger closed 3 years ago

mcwieger commented 3 years ago

I'm running the docker image on Synology. I stopped the package and after this, spotweb didn't work anymore.

I re-created the containers with docker-compose:

version: "2.1"
services:
  spotweb:
    image: jgeusebroek/spotweb
    container_name: spotweb
    restart: unless-stopped
    environment:
     - PUID=1026
     - PGID=101
     - TZ=Europe/Amsterdam
     - SPOTWEB_DB_TYPE=pdo_mysql
     - SPOTWEB_DB_HOST=spotweb-db
     - SPOTWEB_DB_PORT=3306
     - SPOTWEB_DB_NAME=spotweb
     - SPOTWEB_DB_USER=spotweb
     - SPOTWEB_DB_PASS=spotweb
     - "SPOTWEB_CRON_RETRIEVE=* */480 * * *"
    depends_on:
     - spotweb_db
    ports:
     - 8082:80
    volumes:
     - /volume1/docker/spotweb/config:/config

  spotweb_db:
    image: linuxserver/mariadb
    container_name: spotweb-db
    restart: unless-stopped
    environment:
     - PUID=1026
     - PGID=101
     - MYSQL_ROOT_PASSWORD=mysqlrootpassword
     - TZ=Europe/Amsterdam
     - MYSQL_DATABASE=spotweb
     - MYSQL_USER=spotweb
     - MYSQL_PASSWORD=spotweb
    volumes:
     - /volume1/docker/spotweb/mariadb:/config
    ports:
     - 3306:3306

This gives the following error message when trying to connect to spotweb on port 8082:

Unable to connect to database:
SQLSTATE[HY000] [2002] Connection timed out

Please make sure your database server is up and running and your connection parameters are set

When changing SPOTWEB_DB_HOST to 192.168.2.201 (host ip) or 172.18.0.2 (docker ip) the same message is displayed.

Changing to localhost results in:

Unable to connect to database:
SQLSTATE[HY000] [2002] Cannot assign requested address

Please make sure your database server is up and running and your connection parameters are set

Changing to 127.0.0.1 results in:

Unable to connect to database:
SQLSTATE[HY000] [2002] Connection refused

Please make sure your database server is up and running and your connection parameters are set

It doesn't matter if I run the install.php script or change it in dbsettings.inc.php directly.

I tried to connect to mysql in the mariadb container with spotweb@spotweb, that works. So password shouldn't be the issue...

I remember having this issue on initial setup as well. At that time, it seemed it randomly accepted 172.18.0.2 at the 100th try, but I still don't know why or how...

Any ideas?

jgeusebroek commented 3 years ago

What do the logs show for the database? docker-compose logs spotweb_db.

The DB instance get's a docker IP, it should be reachable using the spotweb_db hostname, best not to hardcode an IP as it can change (which is my suspicion)

mcwieger commented 3 years ago

This is the log file:

spotweb_db    | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
spotweb_db    | [s6-init] ensuring user provided files have correct perms...exited 0.
spotweb_db    | [fix-attrs.d] applying ownership & permissions fixes...
spotweb_db    | [fix-attrs.d] done.
spotweb_db    | [cont-init.d] executing container initialization scripts...
spotweb_db    | [cont-init.d] 01-envfile: executing...
spotweb_db    | [cont-init.d] 01-envfile: exited 0.
spotweb_db    | [cont-init.d] 10-adduser: executing...
spotweb_db    |
spotweb_db    | -------------------------------------
spotweb_db    |           _         ()
spotweb_db    |          | |  ___   _    __
spotweb_db    |          | | / __| | |  /  \
spotweb_db    |          | | \__ \ | | | () |
spotweb_db    |          |_| |___/ |_|  \__/
spotweb_db    |
spotweb_db    |
spotweb_db    | Brought to you by linuxserver.io
spotweb_db    | -------------------------------------
spotweb_db    |
spotweb_db    | To support LSIO projects visit:
spotweb_db    | https://www.linuxserver.io/donate/
spotweb_db    | -------------------------------------
spotweb_db    | GID/UID
spotweb_db    | -------------------------------------
spotweb_db    |
spotweb_db    | User uid:    1026
spotweb_db    | User gid:    101
spotweb_db    | -------------------------------------
spotweb_db    |
spotweb_db    | [cont-init.d] 10-adduser: exited 0.
spotweb_db    | [cont-init.d] 30-config: executing...
spotweb_db    | [cont-init.d] 30-config: exited 0.
spotweb_db    | [cont-init.d] 40-initialise-db: executing...
spotweb_db    | [cont-init.d] 40-initialise-db: exited 0.
spotweb_db    | [cont-init.d] 90-custom-folders: executing...
spotweb_db    | [cont-init.d] 90-custom-folders: exited 0.
spotweb_db    | [cont-init.d] 90-warning: executing...
spotweb_db    |
spotweb_db    | ******************************************************
spotweb_db    | ******************************************************
spotweb_db    | *                                                    *
spotweb_db    | *                                                    *
spotweb_db    | *          This image will soon be rebased           *
spotweb_db    | *               from ubuntu to alpine.               *
spotweb_db    | *       Please be aware, this may cause issues       *
spotweb_db    | *     It is strongly recommended to make backups     *
spotweb_db    | *         of your config and databases before        *
spotweb_db    | *       updating your image to the alpine base.      *
spotweb_db    | *                                                    *
spotweb_db    | *                                                    *
spotweb_db    | ******************************************************
spotweb_db    | ******************************************************
spotweb_db    | [cont-init.d] 90-warning: exited 0.
spotweb_db    | [cont-init.d] 99-custom-scripts: executing...
spotweb_db    | [custom-init] no custom files found exiting...
spotweb_db    | [cont-init.d] 99-custom-scripts: exited 0.
spotweb_db    | [cont-init.d] done.
spotweb_db    | [services.d] starting services
spotweb_db    | [services.d] done.
spotweb_db    | Warning: World-writable config file '/etc/mysql/conf.d/custom.cnf' is ignored
spotweb_db    | 210819 17:22:08 mysqld_safe Logging to syslog.
spotweb_db    | Warning: World-writable config file '/etc/mysql/conf.d/custom.cnf' is ignored
spotweb_db    | 210819 17:22:08 mysqld_safe Starting mysqld daemon with databases from /config/databases
mcwieger commented 3 years ago

And spotweb:

spotweb       | Creating database configuration
spotweb       | rm: cannot remove '/var/www/spotweb/dbsettings.inc.php': No such file or directory
spotweb       | Setting (PHP) time zone to Europe/Amsterdam
spotweb       |
spotweb       |  * Starting periodic command scheduler cron
spotweb       |    ...done.
spotweb       | Enabling module rewrite.
spotweb       | To activate the new configuration, you need to run:
spotweb       |   service apache2 restart
spotweb       | Enabling module expires.
spotweb       | To activate the new configuration, you need to run:
spotweb       |   service apache2 restart
spotweb       | Considering dependency filter for deflate:
spotweb       | Module filter already enabled
spotweb       | Module deflate already enabled
spotweb       |  * Restarting Apache httpd web server apache2
spotweb       | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
spotweb       |    ...done.
jgeusebroek commented 3 years ago

Ok, looks ok. Did you change the hostname?

mcwieger commented 3 years ago

Do you mean SPOTWEB_DB_HOST? See my starting post, I tried all possible names/ip addresses, to my knowledge...

jgeusebroek commented 3 years ago

Did you change it to spotweb_db? I didn't see that in your post.

mcwieger commented 3 years ago

I tried creating both containers without docker-compose, with the full command with parameters via the command line. That worked, with the internal docker ip (172.x.x.x).

jgeusebroek commented 3 years ago

Might be related to: https://github.com/jgeusebroek/docker-spotweb/issues/36.

Thanks for the update.