Skip to content
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

docker-compose networking issue cannot connect to the database server #140

Closed
vsotirasqmplus opened this issue Oct 7, 2020 · 9 comments
Closed

Comments

@vsotirasqmplus
Copy link

Creating network "moodle-docker_default" with the default driver
Creating moodle-docker_db_1 ... done
Creating moodle-docker_selenium_1 ... done
Creating moodle-docker_mailhog_1 ... done
Creating moodle-docker_exttests_1 ... done
Creating moodle-docker_webserver_1 ... done
!!!

Error: Database connection failed

It is possible that the database is overloaded or otherwise not running properly.

The site administrator should also check that the database details have been correctly specified in config.php

!!!

Debug info:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: No route to host
Is the server running on host "db" (172.26.0.4) and accepting
TCP/IP connections on port 5432? in [dirroot]/lib/dml/pgsql_native_moodle_database.php on line 176

Error code: dbconnectionfailed
Stack trace: * line 187 of /lib/dml/pgsql_native_moodle_database.php: dml_connection_exception thrown

  • line 340 of /lib/dmllib.php: call to pgsql_native_moodle_database->connect()
  • line 619 of /lib/setup.php: call to setup_DB()
  • line 96 of /config.php: call to require_once()
  • line 78 of /admin/cli/install_database.php: call to require()

moodle-docker-compose commit: origin/HEAD @ 50ec4a0
docker --version: Docker version 19.03.13, build 4484c46d9d
docker-compose --version: docker-compose version 1.25.0, build 0a186604
uname : Linux 4.18.0-193.19.1.el8_2.x86_64

@scara
Copy link
Contributor

scara commented Oct 8, 2020

Hi @vsotirasqmplus,
not sure how it is possible, some extra info required here.

Error: Database connection failed

when you issue bin/moodle-docker-compose up -d (the one printing those reported logs) no actual connection is made by Moodle code to the database.
What is the actual command you issued, in order to replicate your error?
Guessing a series of moodle-docker-compose chained by &&: there, you are IMHO missing bin/moodle-docker-wait-for-db.

uname : Linux 4.18.0-193.19.1.el8_2.x86_64

IINW you're running Docker Engine on top of CentOS/RHEL 8: isn't it?

TIA,
Matteo

@vsotirasqmplus
Copy link
Author

After cloning moodle in /tmp/moodle directory I try to follow the proposed way to do some tests:
And I run it on CEntOS-8 with the versions mentioned

export PATH=$PATH:~/dev/moodle-docker-compose/bin
export MOODLE_DOCKER_DB=pgsql
export MOODLE_DOCKER_WWWROOT=/tmp/moodle/
cp ~/dev/moodle-docker-compose/config.docker-template.php $MOODLE_DOCKER_WWWROOT/config.php
moodle-docker-compose up -d
moodle-docker-wait-for-db

Show docker containers and their IP addresses

docker ps -q | xargs -n 1 docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} {{ .Name }}' | sed 's/ // /'

Initialize Moodle database for manual testing

moodle-docker-compose exec webserver php admin/cli/install_database.php --agree-license --fullname="Docker moodle" --shortname="docker_moodle" --adminpass="test" --adminemail="admin@example.com"

Initialize behat environment

moodle-docker-compose exec webserver php admin/tool/behat/cli/init.php

[..]

Run behat tests

moodle-docker-compose exec -u www-data webserver php admin/tool/behat/cli/run.php --tags=@auth_manual

Initialize phpunit environment

moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php

[..]

Run phpunit tests

moodle-docker-compose exec webserver vendor/bin/phpunit auth_manual_testcase auth/manual/tests/manual_test.php

moodle-docker-compose down

And this is what I get:

moodle-docker-compose_db_1 is up-to-date
Starting moodle-docker-compose_selenium_1 ...
moodle-docker-compose_mailhog_1 is up-to-date
moodle-docker-compose_exttests_1 is up-to-date
Starting moodle-docker-compose_selenium_1 ... done
172.30.0.6 moodle-docker-compose_webserver_1
172.30.0.3 moodle-docker-compose_db_1
172.30.0.5 moodle-docker-compose_mailhog_1
172.30.0.4 moodle-docker-compose_exttests_1
!!!

Error: Database connection failed

It is possible that the database is overloaded or otherwise not running properly.

The site administrator should also check that the database details have been correctly specified in config.php

!!!

Debug info:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: No route to host
Is the server running on host "db" (172.30.0.3) and accepting
TCP/IP connections on port 5432? in [dirroot]/lib/dml/pgsql_native_moodle_database.php on line 176

Error code: dbconnectionfailed
Stack trace: * line 187 of /lib/dml/pgsql_native_moodle_database.php: dml_connection_exception thrown

  • line 340 of /lib/dmllib.php: call to pgsql_native_moodle_database->connect()
  • line 619 of /lib/setup.php: call to setup_DB()
  • line 96 of /config.php: call to require_once()
  • line 78 of /admin/cli/install_database.php: call to require()
    PHP Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: No route to host
    Is the server running on host "db" (172.30.0.3) and accepting
    TCP/IP connections on port 5432? in /var/www/html/lib/dml/pgsql_native_moodle_database.php on line 176
    !!!

    Error: Database connection failed

It is possible that the database is overloaded or otherwise not running properly.

The site administrator should also check that the database details have been correctly specified in config.php

!!!

Debug info:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: No route to host
Is the server running on host "db" (172.30.0.3) and accepting
TCP/IP connections on port 5432? in [dirroot]/lib/dml/pgsql_native_moodle_database.php on line 176

Error code: dbconnectionfailed
Stack trace: * line 187 of /lib/dml/pgsql_native_moodle_database.php: dml_connection_exception thrown

  • line 340 of /lib/dmllib.php: call to pgsql_native_moodle_database->connect()
  • line 619 of /lib/setup.php: call to setup_DB()
  • line 119 of /admin/tool/behat/cli/util_single_run.php: call to require()
    Running single behat site:
    Could not open input file: /var/www/html/vendor/bin/behat
    To re-run failed processes, you can use following command:
    php admin/tool/behat/cli/run.php --tags="@auth_manual" --rerun

Initialising Moodle PHPUnit test environment...
Can not find PHPUnit library, to install use: php composer.phar install
OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: "vendor/bin/phpunit": stat vendor/bin/phpunit: no such file or directory": unknown

@vsotirasqmplus
Copy link
Author

Here is the script
moodle_docker_compose.sh.txt

@vsotirasqmplus
Copy link
Author

Here is the log entries
moodle-docker-compose.log.txt

@scara
Copy link
Contributor

scara commented Oct 8, 2020

Hi @vsotirasqmplus ,
just tested on CentOS 7 (7.8.2003), where docker engine is still supported, and it works:

...
Creating moodle-docker_exttests_1  ... done
Creating moodle-docker_mailhog_1  ... done
Creating moodle-docker_db_1       ... done
Creating moodle-docker_selenium_1 ... done
Creating moodle-docker_webserver_1 ... done
172.18.0.6 moodle-docker_webserver_1
172.18.0.3 moodle-docker_selenium_1
172.18.0.5 moodle-docker_exttests_1
172.18.0.2 moodle-docker_mailhog_1
172.18.0.4 moodle-docker_db_1

Notice: Undefined property: stdClass::$branch in /var/www/html/lib/classes/plugin_manager.php on line 755
-------------------------------------------------------------------------------
== Setting up database ==
-->System
...
++ Success ++
Acceptance tests site installed
Testing environment themes built
Acceptance tests environment enabled on http://webserver, to run the tests use:
vendor/bin/behat --config /var/www/behatdata/behatrun/behat/behat.yml
Running single behat site:
Moodle 4.0dev (Build: 20200827), 38abfb6a01888145878e7175e0431a156f6f1078
Php: 7.2.33, pgsql: 11.9 (Debian 11.9-1.pgdg90+1), OS: Linux 3.10.0-1127.19.1.el7.x86_64 x86_64
Run optional tests:
- Accessibility: No
Server OS "Linux", Browser: "firefox"
Browser specific fixes have been applied. See http://docs.moodle.org/dev/Acceptance_testing#Browser_specific_fixes
Started at 09-10-2020, 04:08
...............

2 scenarios (2 passed)
15 steps (15 passed)
0m11.36s (51.85Mb)
Initialising Moodle PHPUnit test environment...
...
++ Success ++

PHPUnit test environment setup complete.
Moodle 4.0dev (Build: 20200827), 38abfb6a01888145878e7175e0431a156f6f1078
Php: 7.2.33, pgsql: 11.9 (Debian 11.9-1.pgdg90+1), OS: Linux 3.10.0-1127.19.1.el7.x86_64 x86_64
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

..                                                                  2 / 2 (100%)

Time: 660 ms, Memory: 42.00 MB

OK (2 tests, 7 assertions)

Tested using the latest code from master and pulling all the related images having removed the ones already pulled on my docker engine (v19.03.13) to be sure to run the latest code and images of the Moodle Docker Toolbox - no need of the latest Moodle code.

Note: Undefined property: stdClass::$branch is due to MDL-68536.

HTH,
Matteo

@vsotirasqmplus
Copy link
Author

I was driving myself mad:
the centos8 firewall was blocking bridge communications between processes and from processes to the external internet resources
docker/for-linux#957 (comment)

Fast workaround
sudo nano /etc/firewalld/firewalld.conf
in config file change
FirewallBackend=nftables
on
FirewallBackend=iptables
save change and reload firewalld
sudo systemctl restart firewalld.service

it should help you work with docker but I advise rollback this setting when docker provides solution.

@scara
Copy link
Contributor

scara commented Oct 9, 2020

TNX @vsotirasqmplus for sharing the solution!

FYI I still use CentOS 7 to host the Docker Engine, waiting for podman being able to effectively play w/ compose (one day, maybe) to start using CentOS 8 for dev purposes.

HTH,
Matteo

@vsotirasqmplus
Copy link
Author

Should this not become part of the requirements declaration to avoid assumptions for others too?

@scara
Copy link
Contributor

scara commented Oct 9, 2020

Hi @vsotirasqmplus,
not sure since Docker Engine isn't officially supported on RHEL8 or CentOS8 and it is a known issue/decision i.e. you're on your own: Red Hat seems to have somehow blocked the installation of those containerd.io versions above the one which is a dependency of docker-ce to enforce such decision.
Besides, as you wrote, as long as firewalld is enabled, DNS resolution inside docker containers does not work unless you go with the workaround you shared here - or the other options down that comment.
podman is the king of the 8 release, including buildah and skopeo.

Let Moodle HQ tell his thoughts about your proposal.

HTH,
Matteo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants