`curl`命令在Dockerfile中不会返回任何内容,而在任何其他Linux系统中都可以使用
我有一个Docker文件,其中包含:
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
如果安装了curl
则在任何linux命令行中,最后一行命令都会返回echos版本,但是在docker build期间,不会返回任何版本。
@ TarunLalwani的评论让我想到了一个省了很多时间的方法。
这一切都是关于我的resolv.conf
文件没有正确设置,curl无法访问URL; 但是由于我在这之前使用了一些cut
和grep
命令,所以我弄不明白。
我search了一下,发现我应该为resolve.conf
设置所需的configuration,然后在一个RUN
命令中执行curl
,以便能够parsingURL( 在这里描述 )。
我现在有这个Dockerfile
,它工作正常:
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