我有一些 spring boot 微服务。我想使用 docker compose 运行它们。为了确保服务按顺序运行,我使用 .sh 文件在其他服务之前运行其中一个,因为其他微服务依赖于它。bash 脚本文件运行良好,但它会停止调用者容器。我在互联网上搜索并意识到必须在 bash 脚本文件末尾添加一些命令:/cnb/process/web
或./cnb/lifecycle/launcher
才能继续该过程。但显示此消息: /cnb/process/web: No such file or directory
。
Spring Boot 版本:3.2.2
Docker 撰写:3.8
.sh 文件:
#!/bin/bash
# check-config-server-started.sh
apt-get update -y
yes | apt-get install curl
curlResult=$(curl -s -o -I -w "%{http_code}" http://cloud-config-server:8888/actuator/health)
echo "result status code:" "$curlResult"
while [[ ! $curlResult == "200" ]]; do
>&2 echo "Config server is not up yet!"
sleep 2
curlResult=$(curl -s -o -I -w "%{http_code}" http://cloud-config-server:8888/actuator/health)
done
/cnb/process/web
#./cnb/lifecycle/launcher
Docker 撰写文件:
version: "3.8"
services:
cloud-config-server:
container_name: cloud-config-server-container
build:
dockerfile: ./cloud-config-server/Dockerfile
ports:
- "8888:8888"
environment:
- "SERVER_PORT=8888"
networks:
my-compose-net:
restart: on-failure
webapp:
container_name: webapp-container
build:
dockerfile: ./webapp/Dockerfile
ports:
- "8081:8081"
volumes:
- "./check-config-server-started.sh:/usr/local/bin/check-config-server-started.sh"
user: root
entrypoint: [ "check-config-server-started.sh" ]
environment:
- "SPRING_CLOUD_CONFIG_URI=http://cloud-config-server:8888"
depends_on:
- cloud-config-server
networks:
my-compose-net:
restart: on-failure
networks:
my-compose-net: