`curl` command returns nothing in Dockerfile whils

2019-08-18 17:13发布

I have a Docker file containing:

FROM ubuntu
MAINTAINER Zeinab Abbasimazar
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends apt-utils
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y wget unzip curl aptitude
RUN aptitude search curl
RUN VERSION=$(curl myURL 2>&1 | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 | egrep component-[0-9].[0-9].[0-9]$ | cut -d'-' -f3); echo $VERSION

Last line command echos version as expected in any linux command line if curl is installed, but during docker build no version is returned.

1条回答
放我归山
2楼-- · 2019-08-18 17:33

@TarunLalwani's comment led me to a way that saved me a lot of time.

It was all about my resolv.conf file which wasn't set properly and curl was not able to access the URL; but since I used some cut and grep command ahead of that, I couldn't figure it out.

I googled and I found out that I should set my desired configurations for resolve.conf, then execute curl in one RUN command in order to be able to resolve the URL (described here).

I have this Dockerfile now, which works fine:

FROM ubuntu
MAINTAINER Zeinab Abbasimazar
RUN apt-get update
RUN apt-get install -y curl
RUN echo "nameserver myDNS\n" > /etc/resolv.conf; \
    export VERSION=$(curl myURL 2>&1 | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2 | egrep component-[0-9].[0-9].[0-9]$ | cut -d'-' -f3); \
    echo $VERSION
查看更多
登录 后发表回答