RobLoach / drush-docker

:whale: Docker Container to run Drush
http://registry.hub.docker.com/u/drush/drush
Other
19 stars 19 forks source link

Unable to load class Drush\Sql\Sql #1

Open heyyoyo opened 9 years ago

heyyoyo commented 9 years ago

I'm using a personnal web container based on tutum/apache-php linked to the mysql container(image mysql)

in my bootlocal.sh I created an alias for drush like this:

alias drush="docker run drush/drush -ti --rm"

as soon as I try to run drush with database operations, for example drush sqlc I get this error:

Unable to load class Drush\Sql\Sql                                                                                                                                                                   [error]
exception 'Drush\Sql\SqlException' with message 'Unable to find a matching SQL Class. Drush cannot find your database connection details.' in                                                        [error]
/root/composer/vendor/drush/drush/commands/sql/sql.drush.inc:595
Stack trace:
#0 /root/composer/vendor/drush/drush/commands/sql/sql.drush.inc(454): drush_sql_get_class()
#1 [internal function]: drush_sql_cli()
#2 /root/composer/vendor/drush/drush/includes/command.inc(368): call_user_func_array('drush_sql_cli', Array)
#3 /root/composer/vendor/drush/drush/includes/command.inc(219): _drush_invoke_hooks(Array, Array)
#4 [internal function]: drush_command()
#5 /root/composer/vendor/drush/drush/includes/command.inc(187): call_user_func_array('drush_command', Array)
#6 /root/composer/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(62): drush_dispatch(Array)
#7 /root/composer/vendor/drush/drush/drush.php(70): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#8 /root/composer/vendor/drush/drush/drush.php(11): drush_main()
#9 {main}

Any help will be appreciated. thanks

RobLoach commented 9 years ago

Mmm, it likely needs an update to 8.x.

heyyoyo commented 9 years ago

I'm not sure to understand it's supposed to work. In my settings.php my host is equal to db which is the link to my container of mysql defined in container tutum/apache-php Drupal understands this host because php is executed inside this container tutum. But when drush is executed how drush is supposed to know what is this host db ? I hope my question is clear

RobLoach commented 9 years ago

Just updated to 8.0.0-beta11.. Mind testing it? Thanks!

RobLoach commented 9 years ago

Is your database in another container? Will have to share the port with the Drush container.

heyyoyo commented 9 years ago

Hi Rob, Thanks for your update. I just tested it (on another machine) but still drush don't succeed to connect to my db. Yes mysql is in its own container. i'm using the official docker images. I just looked the dockerfile, the regular port 3306 is exposed. Hum by just writing that, I understand that I need also to open this port in my docker-compose.yml file :-)

So my environment that I'm trying to achieve is composed of 3 containers: tutum/apache-php mysql official drush/drush

here is my docker-compose.yml:

web:
  image: tutum/apache-php
  ports:
    - "80:80"
  volumes:
    - /var/www:/var/www
    - /var/www/docker/php.ini:/etc/php5/apache2/conf.d/30-custom.ini
    - /var/www/docker/sites:/etc/apache2/sites-enabled
  links:
    - db:db

db:
  image: mysql
  ports:
    - "3306:3306"
  volumes:
    - /var/lib/boot2docker/mysql:/var/lib/mysql
  environment:
    - MYSQL_ROOT_PASSWORD=root

After executing on a fresh drupal: drush en devel -y I tried to add the uri but with no luck.

docker@boot2docker:/var/www/d7$ drush -l http://d7 en devel -y
Command pm-enable needs a higher bootstrap level to run - you will       [error]
need to invoke drush from a more functional Drupal environment to run
this command.
The drush command 'en devel' could not be executed.                      [error]
Drush was not able to start (bootstrap) the Drupal database.             [error]
Hint: This may occur when Drush is trying to:
 * bootstrap a site that has not been installed or does not have a
configured database. In this case you can select another site with a
working database setup by specifying the URI to use with the --uri
parameter on the command line. See `drush topic docs-aliases` for
details.
 * connect the database through a socket. The socket file may be
wrong or the php-cli may have no access to it in a jailed shell. See
http://drupal.org/node/1428638 for details.

Drush was attempting to connect to:
 Drupal version         :  7.38
 Site URI               :  http://d7
 Database driver        :  mysql
 Database hostname      :  db
 Database port          :  3306
 Database username      :  root
 Database name          :  d7
 PHP configuration      :
 PHP OS                 :  Linux
 Drush script           :  /root/composer/vendor/drush/drush/drush.
                           php
 Drush version          :  8.0-dev
 Drush temp directory   :  /tmp
 Drush configuration    :
 Drush alias files      :
 Drupal root            :  /app
 Site path              :  sites/default
heyyoyo commented 9 years ago

I tried to modify my alias to drush: docker run --rm --link docker_db_1:db -v $(pwd):/app drush/drush

But still no luck.

boreendesign commented 7 years ago

In my case I am using composer with drupal and was getting the same error. I had pulled my drupal instance down but I had not ran composer update in case anyone is getting a similiar error. https://www.lullabot.com/articles/goodbye-drush-make-hello-composer