2017-08-14 101 views
0

我有一個包含泊塢文件:`curl`命令不返回任何在Dockerfile而它在所有其他Linux系統

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 

最後一行命令回聲版本預計在任何Linux命令行如果安裝curl,但在docker build期間沒有返回版本。

+0

它沒有我的系統上也返回任何東西:/ – Ayushya

+0

@Ayushya,這個命令是根據我的需要定製。您沒有足夠的信息來獲取結果。主要問題是它在一個普通的shell上工作,但不能在'Dockerfile'中工作。 –

+0

在'RUN curl -v myURL'之前添加一個調試步驟,看看你得到了什麼? –

回答

0

@ TarunLalwani的評論讓我想到了一種爲我節省了很多時間的方法。

這是關於我的resolv.conf文件,它沒有正確設置,curl無法訪問URL;但由於在此之前我使用了一些cutgrep命令,我無法弄清楚。

我一派,我發現我應該把我所期望的配置爲resolve.conf,那麼爲了能夠解決該URL(described here)在一個RUN命令執行curl

我有這個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