V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
programV2
V2EX  ›  程序员

Drupal 迁移到 Docker,求问如何在 Docker 容器里安装 drush?谢谢

  •  
  •   programV2 · 2020-02-06 17:29:52 +08:00 · 1866 次点击
    这是一个创建于 1549 天前的主题,其中的信息可能已经有所发展或是发生改变。
    前天的求助帖子下有好心的 V 友提醒我可以装 drush 解决我网站无法登陆后台的问题, 但是 查了两天的资料都没搞定. 死活都装不上 drush, 求助 V 友们, 有没有成功迁移到 docker 并使用 drush 的经验分享? 谢谢!
    /t/642016
    12 条回复    2020-02-08 00:52:32 +08:00
    programV2
        1
    programV2  
    OP
       2020-02-06 17:31:27 +08:00
    我进入容器后执行 composer require drush/drush 后显示 没有 composer 这个命令, 然后我用以下代码手动安装:

    php -r "readfile('http://files.drush.org/drush.phar');" > drush && chmod +x drush && mv drush /usr/bin/

    但是执行# /usr/local/bin/drush uli 报错:
    /usr/local/bin/drush: line 2: syntax error: unexpected "("

    请问还有什么办法安装上drush吗? 谢谢!
    programV2
        2
    programV2  
    OP
       2020-02-06 21:25:11 +08:00 via iPhone
    手抖更正 :
    我进入容器后执行 composer require drush/drush 后显示 没有 composer 这个命令, 然后我用以下代码手动安装:

    php -r "readfile('http://files.drush.org/drush.phar');" > drush && chmod +x drush && mv drush /usr/local/bin/

    但是执行# /usr/local/bin/drush uli 报错:
    /usr/local/bin/drush: line 2: syntax error: unexpected "("

    请问还有什么办法安装上drush吗? 谢谢!
    hefish
        3
    hefish  
       2020-02-06 21:41:51 +08:00
    你发行版是哪个发行版,就按哪个发行版处理呗。
    没有 composer 自己装个 composer 呗。
    programV2
        4
    programV2  
    OP
       2020-02-06 22:14:43 +08:00
    @hefish v 友, 请问你是 docker 上装 drupal8 吗? 我看到说 composer 要占 1G 内存, 所以想看看有没有别的方法 , 另外 drush 装上后要如何才能连接另一个 mysql 容器?
    jianixrabbit
        5
    jianixrabbit  
       2020-02-06 23:08:31 +08:00 via Android
    感谢回复者
    Reply 4
    programV2 52 分钟前
    @hefish v 友, 请问你是 docker 上装 drupal8 吗? 我看说 composer 要占 1G 内存
    jianixrabbit
        6
    jianixrabbit  
       2020-02-06 23:14:02 +08:00
    5 楼手抖发错了,不好意思。
    正题:你确定需要 1G 内存?
    hefish
        7
    hefish  
       2020-02-06 23:14:40 +08:00
    亲,composer 跑的时候吃点内存很正常啊。跑完了不就不占内存了吗?
    连接 mysql 容器,自然是用哪个容器的机器名或者 ip 去连了。 看起来你对 docker 不熟悉啊。 还是先熟悉一下 docker
    programV2
        8
    programV2  
    OP
       2020-02-07 00:06:04 +08:00
    @hefish 谢谢回复! 不好意思, 我可能没表达清楚. 我装 Drush 是想要用 drush uli 生成一次性登陆链接, 但是 docker 不同容器之间是独立, 所以我用 volumes: -."/drupal/mysql:/var/lib/mysql" 参数让 drupal 和 mysql 容器共同挂载到宿主机的同一个目录, 这样应该就可以让两个容器互相访问了, 但是我现在执行 drush uli 生成的链接开头却是 http://default/user/reset/1

    然后我跑了下 ./drush status
    Drupal version : 8.5.5
    Site URI : http://default
    Database driver : mysql

    请问两位大佬, 现在还有什么办法可以登陆后台?

    @jianixrabbit
    TangMonk
        9
    TangMonk  
       2020-02-07 17:59:22 +08:00
    这个年代了,为什么要用 Drupal
    programV2
        10
    programV2  
    OP
       2020-02-07 21:26:48 +08:00
    @TangMonk 确实很多坑,这是很早之前用 drupal 建的, 大佬, 我通过删掉 recaptcha 和 captcha 两文件夹并进入数据库清缓存来停用 recaptcha 和 captcha 模块, 登陆没有出现验证码终于进入管理后台, 但是点击后台任意菜单都出错, 请问这可能是什么原因呢? 求 V 友们帮忙看看我的报错日志, 谢谢!



    error log:



    2020/02/07 07:58:56 [error] 6#6: *108 FastCGI sent in stderr: "PHP message: Uncaught PHP Exception Drupal\Component\Plugin\Exception\PluginException: "Plugin (captcha) instance class "Drupal\captcha\Element\Captcha" does not exist." at /var/www/html/core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php line 97" while reading response header from upstream, client: 1.2.3.4, server: example, request: "GET /user/1/edit HTTP/1.1", upstream: "fastcgi://172.19.0.3:9000", host: "example", referrer: "http://example/user/1"

    2020/02/07 07:59:19 [error] 6#6: *170 FastCGI sent in stderr: "PHP message: Uncaught PHP Exception Drupal\Component\Plugin\Exception\PluginException: "Plugin (captcha) instance class "Drupal\captcha\Element\Captcha" does not exist." at /var/www/html/core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php line 97" while reading response header from upstream, client: 1.2.3.4, server: example, request: "GET /admin HTTP/1.1", upstream: "fastcgi://172.19.0.3:9000", host: "example", referrer: "http://example/user/1"

    access log:

    1.2.3.4 - - [07/Feb/2020:07:58:56 +0000] "GET /user/1/edit HTTP/1.1" 500 537 "http://example/user/1" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
    1.2.3.4 - - [07/Feb/2020:07:58:56 +0000] "GET /modules/admin_toolbar/admin_toolbar_tools/misc/icons/ffffff/d8-item.svg HTTP/1.1" 200 1499 "http://example/modules/admin_toolbar/admin_toolbar_tools/css/tools.css?pc5ppi" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
    1.2.3.4 - - [07/Feb/2020:07:59:00 +0000] "GET /modules/coffee/images/icons/bebebe/coffee.svg HTTP/1.1" 200 1947 "http://example/modules/coffee/css/coffee.css?pc5ppi" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
    1.2.3.4 - - [07/Feb/2020:07:59:19 +0000] "GET /admin HTTP/1.1" 500 537 "http://example/user/1" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
    1.2.3.4 - - [07/Feb/2020:07:59:23 +0000] "GET /core/misc/icons/ffffff/hamburger.svg HTTP/1.1" 200 510 "http://example/core/modules/toolbar/css/toolbar.icons.theme.css?pc5ppi" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"
    hefish
        11
    hefish  
       2020-02-08 00:22:47 +08:00
    我想 lz 的想法可能是跑两个容器,一个容器跑 Mysql,一个容器跑 php+nginx,然后在 nginx+php 的环境里再跑 drupal,
    这个,可以先建一个 docker 的 network,然后再建一个 mysql 的容器,跑在这个 network 上,另一个容器是 php+nginx,也跑在这个 Network 上,当然容器与容器是隔离的,然后 php 要访问 mysql,自然是通过 tcp:3306 来访问。 至于数据库文件,随便是映射到 host,还是直接放在 container,都可以。总之对 Php 来说,那个 container 就是提供 mysql 服务的。

    我只能说这么多了。
    programV2
        12
    programV2  
    OP
       2020-02-08 00:52:32 +08:00
    @hefish 谢谢大佬回复! 我跑了 3 个容器,一个容器跑 Mysql,一个容器跑 php 另外一个 nginx, 在 php 的环境里再跑 drupal,我在 docker-compose.yml 中的 php 和 mysql 都设置了 volumes: -."/drupal/mysql:/var/lib/mysql" , 这样理论两个容器之间就可以互相访问了, 又在 php 容器上手动安装了 drush, 然后现在登陆进 php 容器执行 ./drush --uri=http://serebiomedical.com pm-uninstall -y captcha 报错如下, 这个有可能是什么原因呢?
    因为 drush 命令涉及到要访问 mysql 容器, 是还要再加什么参数吗?
    另外大佬您方便的话可不可以帮我看看上面#10 楼我贴出的报错日志. 万分感谢! 

    Command pm-uninstall needs a higher bootstrap level to run - you will need [error]
    to invoke drush from a more functional Drupal environment to run this
    command.
    The drush command 'pm-uninstall captcha' 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.
    * connect to the database through a cli command using the
    --defaults-extra-file parameter to pass credentials through a tmp file.
    This method can break if other credentials are specified in a ~/.my.cnf
    file in your home directory. You may have to delete or rename the
    ~/.my.cnf file in your home directory.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2445 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:29 · PVG 20:29 · LAX 05:29 · JFK 08:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.