gpt4 book ai didi

docker - 强制 docker 接受并继续构建具有非零响应/代码的图像的方法

转载 作者:行者123 更新时间:2023-12-02 18:01:37 25 4
gpt4 key购买 nike

我有以下 dockerfile,使用 Centos:latest 作为基本镜像非常简单。
docker 文件在 0 以外的任何命令上作为错误代码/代码退出
yum check-update 返回状态码 100 表示操作成功

docker文件如下

FROM centos:latest
MAINTAINER xyz (xyz@gmail.com)
ENTRYPOINT ["/bin/sh", "-lc", "ocp-indent"]
RUN yum -y check-update

当我尝试构建图像时,该过程按如下方式运行,但它在没有成功构建图像的情况下被杀死
Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM centos:latest
latest: Pulling from library/centos
7dc0dca2b151: Pull complete
Digest:
sha256:b67d21dfe609ddacf404589e04631d90a342921e81c40aeaf3391f6717fa5322
Status: Downloaded newer image for centos:latest
---> 49f7960eb7e4
Step 2/4 : MAINTAINER xyz (xyz@gmail.com)
---> Running in c5284bbfb10e
---> b2334a38cc19
Removing intermediate container c5284bbfb10e
Step 3/4 : ENTRYPOINT /bin/sh -lc ocp-indent
---> Running in 55b9adafca35
---> 02df626e85d6
Removing intermediate container 55b9adafca35
Step 4/4 : RUN yum check-update
---> Running in 3f9d47e74522
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirror.its.dal.ca
* extras: centos.les.net
* updates: centos.les.net

binutils.x86_64 2.27-28.base.el7_5.1
updates
gnupg2.x86_64 2.0.22-5.el7_5
updates
python.x86_64 2.7.5-69.el7_5
updates
python-libs.x86_64 2.7.5-69.el7_5
updates
**The command '/bin/sh -c yum check-update' returned a non-zero code: 100**

最佳答案

yum check-update预期 如果更新可用,以状态 100 退出,如其文档中所述:

  • check-update

    Implemented so you could know if your machine had any updates that needed to be applied without running it interactively. Returns exit value of 100 if there are packages available for an update. Also returns a list of the packages to be updated in list format. Returns 0 if no packages are available for update. Returns 1 if an error occurred. Running in verbose mode also shows obsoletes.



同样,docker RUN命令应在任何非零退出状态下终止。如果要强制命令忽略 100 的退出状态(但仍将其他失败视为错误),可以按如下操作:
RUN yum -y check-update || { rc=$?; [ "$rc" -eq 100 ] && exit 0; exit "$rc"; }

那个 Docker RUN命令将任何非零退出状态视为失败是标准的 UNIX 约定(唯一成功的退出状态为 0),并在 dockerfile/containerbackend.go 中明确实现。 :
if status := <-waitC; status.ExitCode() != 0 {
close(finished)
logCancellationError(cancelErrCh,
fmt.Sprintf("a non-zero code from ContainerWait: %d", status.ExitCode()))
return &statusCodeError{code: status.ExitCode(), err: status.Err()}
}

关于docker - 强制 docker 接受并继续构建具有非零响应/代码的图像的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51526781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com