2

Jenkins build is failing on all nodes except one I am getting below error while building a docker image

Could not build image: The command '/bin/sh -c apk --no-cache update &&     apk --no-cache add python py-pip py-setuptools ca-certificates groff &&     pip --no-cache-dir install cfn-lint &&     pip --no-cache-dir install awscli==${AWS_CLI_VERSION}' returned a non-zero code: 4 -> [Help 1]

My docker file is

FROM openjdk:8-jre-alpine

# Versions: https://pypi.python.org/pypi/awscli#downloads
ENV AWS_CLI_VERSION 1.16.100

RUN apk --no-cache update && \
    apk --no-cache add python py-pip py-setuptools ca-certificates groff && \
    pip --no-cache-dir install cfn-lint && \
    pip --no-cache-dir install awscli==${AWS_CLI_VERSION}

How do I solve this issue ?

devops
  • 1,121
  • 5
  • 20
  • 50
  • try with `RUN set -x && apk --no-cache update ...` you will see more info – Ntwobike Jul 02 '19 at 15:52
  • If its only failing on one particular jenkins node then try to cleanup docker images from that node and retry again. – mchawre Jul 02 '19 at 15:52
  • Just tested and it works for me. My advice is to try to break this `RUN` command into multiple `RUN` in order to figure out which command is returning error code `4`. – Romain Jul 02 '19 at 16:16

2 Answers2

1

Just tested and it works for me, so it could be related to some networking issue. My advice is to try to break this RUN command into multiple RUN (or at least in two) in order to figure out which command is returning error code 4.

FROM openjdk:8-jre-alpine

# Versions: https://pypi.python.org/pypi/awscli#downloads
ENV AWS_CLI_VERSION 1.16.100

RUN apk --no-cache update && \
    apk --no-cache add python py-pip py-setuptools ca-certificates groff

RUN pip --no-cache-dir install cfn-lint && \
    pip --no-cache-dir install awscli==${AWS_CLI_VERSION}

An hypothesis

Since apk uses wget

In addition to local repositories, the apk utility uses busybox wget to fetch packages using http:, https: or ftp: protocols. The following is a valid repository file:

The error code 4 could come from wget and, if it's so, it's meaning is

Network failure.

So my guess is that some agents have no access to the location from where the packages are downloaded. Please check if you have access to http://dl-cdn.alpinelinux.org from these agents. To do so, try to run a wget in the Dockerfile with the first fetch made by apk.

RUN wget http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
Romain
  • 19,910
  • 6
  • 56
  • 65
  • I am getting this error :Step 3/5 : RUN apk --no-cache update && apk --no-cache add python py-pip py- setuptools ca-certificates groff ---> [Warning] IPv4 forwarding is disabled. Networking will not work. – devops Jul 03 '19 at 13:47
  • Good we have the confirmation, it's a networking issue. I'm not a specialist, you could have a look to this question: https://stackoverflow.com/questions/41453263/docker-networking-disabled-warning-ipv4-forwarding-is-disabled-networking-wil – Romain Jul 03 '19 at 15:05
0

I had a similar issue, and I had to remove invalid proxies entry from ~/.docker/config.json.

mico
  • 12,730
  • 12
  • 59
  • 99
alex
  • 1,757
  • 4
  • 21
  • 32