强制 docker 接受并继续使用非零 response/code 构建图像的方法
Way to force docker to accept and proceed with building the image with a non zero response/code
我有以下 docker 文件,它使用 Centos:latest 作为基础图像非常简单。
docker 文件在除 0 以外的任何命令上作为错误退出 code/code
yum check-update returns 状态代码 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 文件,它使用 Centos:latest 作为基础图像非常简单。 docker 文件在除 0 以外的任何命令上作为错误退出 code/code yum check-update returns 状态代码 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()}
}