This error is mostly due to dependency issues between third party modules requiring magento native module before they’ve been installed. So the solution is to:
1. Enable all the modules
php bin/magento module:enable --all
2. Disable third party modules before the setup:install
php bin/magento module:status | grep -v Magento | grep -v List | grep -v None | grep -v -e '^$' | xargs php bin/magento module:disable
Another cause is the absence of the env.php file here a generic content of this file:
echo "<?php return ['db' => [ 'table_prefix' => '', 'connection' => [ 'default' => [ 'host' => 'mysql', 'dbname' => 'magento', 'username' => 'root', 'password' => 'magento', 'model' => 'mysql4', 'engine' => 'innodb', 'initStatements' => 'SET NAMES utf8;', 'active' => '1' ] ]]];" > app/etc/env.php