bash - 如何在 Docker Compose 中运行多个 bash 命令(使用管道)
问题描述
我在 Docker Compose 中有一个冗长的 bash 命令:
command: bash -c 'wait-for-it emul:4000 && (firebase-prime ... | grep -v -E "Do not use with production credentials") && npx vite --port 3000'
如果firebase-prime
没有找到,或者它会失败,整个命令仍然会通过并且 Docker Compose 会继续运行。如何让它失败,以及如何让 Docker Compose 关闭所有依赖服务?
解决方案
实验:
$ bash -c 'false | cat' && echo a
a
$ bash -c 'set -o pipefail; false | cat' && echo a
$ bash -o pipefail -c 'false | cat' && echo a
添加-o pipefail
似乎是最简单的语法。
command: bash -o pipefail -c 'wait-for-it emul:4000 && (firebase-prime ... | grep ...)`
推荐阅读
- c++ - 将 _stprintf_s 保存在 txt 文件中
- django - 使用单独的现有用户数据库进行 django 登录
- javascript - 想要在对象键中的__键之后拆分键并过滤
- c++ - printf有替代品吗?
- android - 无法从 gradle 命令行执行 testng.xml 文件
- list - 在 Applescript 中不使用 if 语句为变量列表赋值
- php - 我应该在加密中使用哪个 php 7.2 函数和哪个加密算法来获得 16 个十六进制字符的密文?
- python - 如何使用正则表达式提取多个字符串
- c++ - 为什么我的 txt 文件无法在 C++ 中打开?
- certificate - 如何在corda中使用自定义证书