下载脚本
GitHub地址:https://github.com/vishnubob/wait-for-it
脚本文件地址:https://static.naste.top:1024/shell/wait-for-it.sh
脚本地址:https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh
使用
1 2 3 4 5 6 7
| wait-for-it.sh host:port [-s] [-t timeout] [-- command args] -h HOST | --host=HOST 测试中的主机或IP -p PORT | --port=PORT 测试中的TCP端口,或者,将主机和端口指定为host:port -s | --strict 仅在测试成功时执行子命令 -q | --quiet 不输出任何状态消息 -t TIMEOUT | --timeout=TIMEOUT 超时(秒),零表示无超时 -- COMMAND ARGS 测试完成后使用args执行命令
|
1 2
| # 需要将脚本挂载到容器里面,如果nacos启动成功,将执行项目启动命令,否则在60秒后容器启动失败 ./wait-for-it.sh nacos:8848 -s -t 60 -- 项目的启动命令
|
dockerfile
Dockerfile中ENTRYPOINT
一个""
只能传入一个参数,不能多个参数同时放在一个""
,Docker会将其认为是一个参数使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| FROM openjdk:8-jre
MAINTAINER xiaofei
WORKDIR /xiaofei/xiaofei-blog/xiaofei-utils
VOLUME /xiaofei/xiaofei-blog/xiaofei-utils
COPY ./jar/xiaofei-utils.jar ./jar/xiaofei-utils.jar COPY ./jar/lib ./jar/lib COPY ./wait-for-it.sh ./
RUN chmod +x ./wait-for-it.sh
ENTRYPOINT ["./shell/wait-for-it.sh","nacos:8848","-s","-t","120", "--","java","-jar","-Dloader.path=./jar/lib","./jar/xiaofei-utils.jar"]
|
使用开源的wait-for-it脚本延迟Docker容器启动时间