`curl`命令在Dockerfile中不返回任何内容,而在其他所有linux系统中均有效 [英] `curl` command returns nothing in Dockerfile whilst it works in every other linux system

查看:454
本文介绍了`curl`命令在Dockerfile中不返回任何内容,而在其他所有linux系统中均有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下内容的Docker文件:

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

如果 curl 已安装,但在Docker构建期间未返回任何版本。

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

推荐答案

@TarunLalwani的评论使我想到了一种节省大量时间的方法。

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

这与我的 resolv.conf 文件有关,该文件的设置不正确并且curl无法访问网址;但是由于在此之前我使用了 cut grep 命令,所以无法弄清楚。

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.

我搜索了一下,发现应该为 resolve.conf 设置所需的配置,然后执行 RUN 命令中> curl 以便能够解析URL(在此描述)。

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).

我有这个 Dockerfile 现在可以正常工作:

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

这篇关于`curl`命令在Dockerfile中不返回任何内容,而在其他所有linux系统中均有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆