在docker compose中,我有以下命令:
command: bash -c 'while [[ "$(curl --connect-timeout 2 -s -o /dev/null -w ''%{http_code}'' https://mock-server:4000/readiness)" != "200" ]]; do echo ..; sleep 5; done; echo backend is up; npm start'
等待直到模拟服务器启动,然后为后端运行启动命令:
backend:
build:
context: ./test
dockerfile: Dockerfile
command: bash -c 'while [[ "$(curl --connect-timeout 2 -s -o /dev/null -w ''%{http_code}'' https://mock-server:4000/readiness)" != "200" ]]; do echo ..; sleep 5; done; echo backend is up; npm start'
ports:
- "3015:3015"
depends_on:
- couchdb
- redis
- mock-server
user: root
但是出现以下错误:
ERROR: Invalid interpolation format for "command" option in service "backend": "bash -c 'while [[ "$(curl --connect-timeout 2 -s -o /dev/null -w ''%{http_code}'' https://uds-mock-server:4000/readiness)" != "200" ]]; do echo ..; sleep 5; done; echo backend is up;; npm start'"
我看不到我的命令出了什么问题。 任何帮助表示赞赏
答案 0 :(得分:8)
您需要使用$
转义$$
command: bash -c 'while [[ "$(curl --connect-timeout 2 -s -o /dev/null -w ''%{http_code}'' https://mock-server:4000/readiness)" != "200" ]]; do echo ..; sleep 5; done; echo backend is up; npm start'
command: bash -c 'while [[ "$$(curl --connect-timeout 2 -s -o /dev/null -w ''%{http_code}'' https://mock-server:4000/readiness)" != "200" ]]; do echo ..; sleep 5; done; echo backend is up; npm start'
那应该解决build problem