如何使 docker 失败或检查版本是否存在
How to make docker fail or check version exists
我有 maven 运行 a bash 可以用 Docker.
构建一些东西
<plugin>
...
<artifactId>maven-antrun-plugin</artifactId>
...
<exec executable="${basedir}/generate.sh" failonerror="true">
<arg value="${thrift.version}" />
...
bash 脚本运行如下:
for file in src/main/thrift/*.thrift; do
echo "Compiling ${file}"
docker run {...} thrift:${THRIFT_VERSION} thrift {...}
done
我的问题是,当 Docker 找不到我请求的版本时,它会在控制台中显示一个错误,但它不会 "fail":它只是继续构建。
[exec] Compiling src/main/thrift/amsException.thrift
[exec] docker: Tag 0.9.0 not found in repository docker.io/library/thrift.
[exec] See 'docker run --help'.
[exec] Unable to find image 'thrift:0.9.0' locally
因此 maven 说
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
如何在找不到版本时让 Docker 抛出错误?我的最终目标是在发生这种情况时 Maven 无法全新安装。
干杯!
您可以检查 docker run
退出代码。如果它不是 0,则中止您的脚本。
for file in src/main/thrift/*.thrift; do
echo "Compiling ${file}"
docker run {...} thrift:${THRIFT_VERSION} thrift {...}
if [ $? != 0 ]; then
exit -1
fi
done
我有 maven 运行 a bash 可以用 Docker.
构建一些东西<plugin>
...
<artifactId>maven-antrun-plugin</artifactId>
...
<exec executable="${basedir}/generate.sh" failonerror="true">
<arg value="${thrift.version}" />
...
bash 脚本运行如下:
for file in src/main/thrift/*.thrift; do
echo "Compiling ${file}"
docker run {...} thrift:${THRIFT_VERSION} thrift {...}
done
我的问题是,当 Docker 找不到我请求的版本时,它会在控制台中显示一个错误,但它不会 "fail":它只是继续构建。
[exec] Compiling src/main/thrift/amsException.thrift
[exec] docker: Tag 0.9.0 not found in repository docker.io/library/thrift.
[exec] See 'docker run --help'.
[exec] Unable to find image 'thrift:0.9.0' locally
因此 maven 说
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
如何在找不到版本时让 Docker 抛出错误?我的最终目标是在发生这种情况时 Maven 无法全新安装。
干杯!
您可以检查 docker run
退出代码。如果它不是 0,则中止您的脚本。
for file in src/main/thrift/*.thrift; do
echo "Compiling ${file}"
docker run {...} thrift:${THRIFT_VERSION} thrift {...}
if [ $? != 0 ]; then
exit -1
fi
done