lando中有类似docker exec的命令吗?

Is there a command similar to docker exec in lando?

我们在 lando 和非 lando 环境中使用我们的开发环境。有没有办法从 lando 外部触发类似于 docker exec 的 shell 脚本?

lando exec 显然不起作用,它也不是标准命令的一部分,但也许有一种创建它或将其添加为插件的方法?

事实证明,lando 将此构建作为 tooling api 的一部分。它不允许“自由式”命令,但您可以在 .lando.yml.

中预定义您喜欢的任何有用的快捷方式

我们案例中的一个简单示例:

name: my_project
recipe: drupal9
config:
  database: mariadb
  drush: ^10
  php: '7.4'
  webroot: ./web
tooling:
  cex:
    service: appserver
    description: Export the drupal config
    cmd: './scripts/cex.sh'
  cim:
    service: appserver
    description: Install dependencies and import the latest config.
    cmd: './scripts/cim.sh'

如果需要root权限,只需添加user: root

在上面的例子中,你可以简单地调用

lando cexlando cim,触发自定义命令。

实际上有一种比使用工具 API 执行一次性命令更好的方法,这也更类似于 docker exec:

# Opens an interactive terminal inside container
lando ssh

# Runs a specified command inside container
lando ssh -c "ls -la /"

您可以更改目标 service/container 和运行命令的执行用户:

  --command, -c   Run a command in the service
  --service, -s   SSH into this service [default: "appserver"]
  --user, -u      Run as a specific user

在此处查看 lando ssh 的完整文档: https://docs.lando.dev/basics/ssh.html#usage