命令在 docker 容器内工作,但因 docker exec 而失败

Command works inside a docker container but fails with docker exec

我正在使用容器化 Vespa.ai 数据库,我想从主机执行以下命令:

  1. vespa-停止服务
  2. vespa-remove-index
  3. vespa-start-services

如果我在附加容器后从我的 shell 执行以下 vespa-stop-services && vespa-remove-index && vespa-start-services,它工作正常。但是当我使用 docker exec 时它失败了。

我尝试了以下命令:

docker exec bash -c 'vespa-stop-services && vespa-remove-index && vespa-start-services'

docker exec bash -l 'vespa-stop-services && vespa-remove-index && vespa-start-services'

我成功执行这些命令的唯一方法是按顺序执行它们,我想避免这种情况:

docker exec bash -l 'vespa-stop-services'

docker exec bash -l 'vespa-remove-index'

docker exec bash -l 'vespa-start-services'

我做错了什么? 提前致谢!

从父主机系统运行ning 时需要指定这些命令的位置

以下 works/should 工作:

docker exec vespa bash -c "/opt/vespa/bin/vespa-stop-services && /opt/vespa/bin/vespa-remove-index -force && /opt/vespa/bin/vespa-start-services"

注意-force,在删除数据之前不会要求确认,还要注意索引不是唯一的持久数据,配置状态仍然保留。

名为 'vespa' 的 docker 容器的示例 运行:

docker exec vespa bash -c "/opt/vespa/bin/vespa-stop-services && /opt/vespa/bin/vespa-remove-index -force && /opt/vespa/bin/vespa-start-services"
Executing /opt/vespa/libexec/vespa/stop-vespa-base.sh
config-sentinel was running with pid 7788, sending SIGTERM
Waiting for exit (up to 15 minutes)
.. DONE
configproxy was running with pid 7666, sending SIGTERM
Waiting for exit (up to 15 minutes)
. DONE
[info] You have 23088 kilobytes of data for cluster msmarco
[info] For cluster msmarco distribution key 0 you have:
[info] 23084 kilobytes of data in var/db/vespa/search/cluster.msmarco/n0
[info] removing data:  rm -rf var/db/vespa/search/cluster.msmarco/n0
[info] removed.

Running /opt/vespa/libexec/vespa/start-vespa-base.sh
Starting config proxy using tcp/localhost:19070 as config source(s)
runserver(configproxy) running with pid: 10553
Waiting for config proxy to start
config proxy started after 1s (runserver pid 10553)
runserver(config-sentinel) running with pid: 10679