linuxserver / docker-bookstack

A Docker container for the BookStack documentation wiki
GNU General Public License v3.0
762 stars 108 forks source link

connection to mysql server with specific port not working. #88

Closed ghost closed 3 years ago

ghost commented 3 years ago

linuxserver.io


Expected Behavior

Bookstack app should connect to use mysql running on 10.1.1.50:3315. (ip and port should be considered which is defined in docker-compose.yml file)

Current Behavior

When Providing DB_PORT environment variable in docker-compose.yml file, is ignored by the image and still tries to connect to default mysql port 3306.

Steps to Reproduce

  1. docker-compose.yml file:
    
    version: "2"
    services:
    bookstack:
    image: ghcr.io/linuxserver/bookstack
    container_name: bookstack
    environment:
      - PUID=1000
      - PGID=1000
      - APP_URL=localhost
      - DB_HOST=10.1.1.50
      - DB_PORT=3315
      - DB_DATABASE=bookstack
      - DB_USER=bookstack
      - DB_PASS=bookstack
    volumes:
      - /path/to/data:/config
    ports:
      - 80:80
    restart: unless-stopped

networks: bookstack-network: external: name: bookstack



## Environment
**OS:** : tried on Linux Debian and also on Linux Ubuntu and also on MacOs same issue on all of this OS
**CPU architecture:** x86_64
**How docker service was installed:**
<!--- ie. from the official docker repo, from the distro repo, nas OS provided, etc. -->
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
Docker service installed from official instruction here : https://docs.docker.com/get-docker/

## Command used to create docker container (run/create/compose/screenshot)
<!--- Provide your docker create/run command or compose yaml snippet, or a screenshot of settings if using a gui to create the container -->
docker-compose up

## Docker logs
<!--- Provide a full docker log, output of "docker logs bookstack" -->
 1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client")

After debugging found out that above log generated because of mysql server port is not considered as defined in docker-compose.yml (DB_PORT=3315) but tries to connect to default port of mysql server 3306 which is not port of mysql server in mycase. 

Thank you for help. Please write me if you need more information. 
tobbenb commented 3 years ago

There isn't a env variable called DB_PORT, so that will not work. Add the port in the DB_HOST env variable like DB_HOST=10.1.1.50:3307 You should also not use localhost as the APP_URL, as that is only inside the container and not localhost on your docker host. Also your volume should be changed from /path/to/data to something specific for you.

Make sure bookstack is in the same network as your SQL server.

I tested it locally using our mariadb container and I can't reproduce your issue.

ghost commented 3 years ago

@tobbenb Thanks for reply.

in my setup bookstack container and MySQL server runs on different machine (but connected to same network)

I have tried what you said. When I use DB_HOST=10.1.1.50:3315 with MySql server Log shows below error. bookstack | nc: getaddrinfo: Name does not resolve

So Do you mean by having SQL server in same network means same docker network or it can be in same network where ports are exposed. As you tested with Mariadb do you think that with MySql it do not work? I have just tried with Mariadb but it have same issue bookstack | nc: getaddrinfo: Name does not resolve

So database should be in the same docker network in order it to work? Or MySQL server can be run on different machine (other then where bookstack docker container runs)? Thanks.

tobbenb commented 3 years ago

You have to wait a little bit when you start up the container as it checks the availability of the SQL server using port 3306, but will continue after a while. So bookstack | nc: getaddrinfo: Name does not resolve is expected.

You have still not supplied the container log as asked either.

You need to be able to ping the SQL server from within bookstack container. If you use the same docker network, you can specify the container name as the host, if not, you have to use the host IP. Seeing you are running it on another computer, you need to use the IP.

ghost commented 3 years ago

I have checked I can ping to the MySql server from bookstack container. I have waited as you have said and it proceed further. And I have below issue. user have full writes to database but still error.

With MySql Server 8.0

bookstack    | nc: getaddrinfo: Name does not resolve
bookstack    | nc: getaddrinfo: Name does not resolve
bookstack    | 
bookstack    |    Illuminate\Database\QueryException  : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = bookstack and table_name = migrations and table_type = 'BASE TABLE')
bookstack    | 
bookstack    |   at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
bookstack    |     665|         // If an exception occurs when attempting to run a query, we'll format the error
bookstack    |     666|         // message to include the bindings with SQL, which will make this exception a
bookstack    |     667|         // lot more helpful to the developer instead of just the database's errors.
bookstack    |     668|         catch (Exception $e) {
bookstack    |   > 669|             throw new QueryException(
bookstack    |     670|                 $query, $this->prepareBindings($bindings), $e
bookstack    |     671|             );
bookstack    |     672|         }
bookstack    |     673|
bookstack    | 
bookstack    |   Exception trace:
bookstack    | 
bookstack    |   1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client")
bookstack    |       /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31
bookstack    | 
bookstack    |   2   PDOException::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]")
bookstack    |       /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
bookstack    | 
bookstack    |   Please use the argument -v to see more details.
bookstack    | [cont-init.d] 50-config: exited 0.
bookstack    | [cont-init.d] 99-custom-files: executing... 
bookstack    | [custom-init] no custom files found exiting...
bookstack    | [cont-init.d] 99-custom-files: exited 0.
bookstack    | [cont-init.d] done.
bookstack    | [services.d] starting services
bookstack    | [services.d] done.

@tobbenb

I was checking on internet and found article for this bug https://bobcares.com/blog/mysql-the-server-requested-authentication-method-unknown-to-the-client/

The preferred auth plugin for Mysql 8.0+ version is caching_sha2_password.

I hope this helps may be to update dependency library in docker image. Thanks

tobbenb commented 3 years ago

You have the workaround in the link. From what I read, this is an issue with PHP and it's fixed in 7.4. Once we rebase to alpine 3.13, the PHP version will be bumped to 7.4 and is should work without the MySQL workaround.