写法1
version: '3'
services:
demo:
entrypoint: ["echo","hello"]
command: bash -c "command1 && command2 && command3"
多行写法2
version: '3'
services:
demo:
entrypoint: ["echo","hello"]
# > 可选
command: >
bash -c "command1 &&
command2 &&
command3"
多行写法3
version: '3'
services:
demo:
entrypoint: ["echo","hello"]
command:
- /bin/bash
- -c
- |
KAFKA_CLUSTER_ID=$$(/opt/bitnami/kafka/bin/kafka-storage.sh random-uuid)
echo "$$KAFKA_CLUSTER_ID"
/opt/bitnami/kafka/bin/kafka-storage.sh format -t "\$KAFKA_CLUSTER_ID" -c /opt/bitnami/kafka/config/kraft/server.properties
/opt/bitnami/kafka/bin/kafka-server-start.sh /opt/bitnami/kafka/config/kraft/server.properties
Tips:
当您的配置需要文字美元符号时,可以使用 $$(双美元符号)进行转义。这还可以防止 Compose 内插值,因此 $$ 允许您引用不希望由 Compose 处理的环境变量
https://github.com/docker/compose/issues/4485
并行写法
最后一行不要,就是前面几个后台运行,最后一个直接运行
version: '3'
services:
demo:
command:
- /bin/bash
- -c
- |
command1 &
command2 &
command3
参考 :https://qastack.cn/programming/30063907/using-docker-compose-how-to-execute-multiple-commands