Why do I get a Drupal\Core\DependencyInjection\ContainerNotInitializedException exception error? I am using Drupal 8.1.3, Drush 8.1.7, and PHP 5.6.2 on a Mac OS X.

I've installed a fresh Drupal 8 site demo from Zircon on a local MAMP stack. When I try to run watchdog show, and some other commands, I get the following error:


  Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. in Drupal::getContainer() (line 129 of /Applications/MAMP/htdocs/example/docroot/core/lib/Drupal.php).


I was able to run the following commands successfully:

drush cr
drush version
drush status


I've just updated to latest version of drush, but this is my first time seeing this error.

Also, drush pm-update returns: 


  Command pm-update needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to run this command.


Edit/Update:

Here is the output of drush status:

Drupal version         :  8.1.3                                                                                                      
 Site URI               :  http://default                                                                                             
 Database driver        :  mysql                                                                                                      
 Database hostname      :  localhost                                                                                                  
 Database port          :  3306                                                                                                       
 Database username      :  ******                                                                                                    
 Database name          :  ******                                                                                                    
 PHP configuration      :  /Applications/MAMP/bin/php/php5.6.2/conf/php.ini                                                           
 PHP OS                 :  Darwin                                                                                                     
 Drush script           :  /usr/local/bin/drush                                                                                       
 Drush version          :  8.1.7                                                                                                      
 Drush temp directory   :  /tmp                                                                                                       
 Drush configuration    :                                                                                                             
 Drush alias files      :                                                                                                             
 Drupal root            :  /Applications/MAMP/htdocs/example/docroot                                                                  
 Drupal Settings File   :  sites/default/settings.php                                                                                 
 Site path              :  sites/default                                                                                              
 Sync config path       :  sites/default/files/config_pHswhbzOqqMuWn7c6kYMbap6DKcyXxItrvbtsCQeJYoQ04xTi19pOZywbF8KZ8Wrx43VrLsVMw/sync


The user interface does work.

Update: I checked some of my other projects (Drupal 7 and 8 sites), for which drush worked perfectly fine on, and they are throwing errors with the same Drush command, which tells me it's probably not a Drupal 8 problem but probably due to changes I made on my dev platform. I had installed Composer and upgraded Drush, and other related changes.
I had the same problem with Drush throwing an exception for a test site on localhost. I was able to access the site from the browser, from where I didn't get any error message, not even a message from a exception handler. This puzzled me, since the site was clearly working.

It started to work again when I changed the file permissions for the Drupal files. The user account I was using to execute the command line was missing the permission to write in some directories.