Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dockerfile wget失败_Docker_Dockerfile - Fatal编程技术网

Dockerfile wget失败

Dockerfile wget失败,docker,dockerfile,Docker,Dockerfile,我有以下代码 RUN apt-get update RUN apt-get install -y wget #install wget lib RUN mkdir -p example && cd example #create folder and cd to folder RUN WGET -r https://host/file.tar && tar -xvf *.tar # download tar file to example fo

我有以下代码

RUN apt-get update
RUN apt-get install -y wget     #install wget lib
RUN mkdir -p example && cd example     #create folder and cd to folder
RUN WGET -r https://host/file.tar && tar -xvf *.tar   # download tar file to example folder and untar it in same folder
RUN rm -r example/*.tar # remove the tar file
RUN MV example/foo example/bar # rename untar directory from foo to bar
但我得到以下错误:

/bin/sh: 1: WGET: not found
tar: example/*.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

我是docker的新手。

docker文件中的每个后续运行命令都将位于/目录的上下文中。因此,您的.tar文件不在example/目录中,它实际上应该在/目录中,因为您的“cd to the folder”对于后续的运行命令没有任何意义。在运行wget之前,不要执行cd示例,而要执行WORKDIR示例,例如:

或者,添加cd示例&&。。。在要在示例目录中执行的任何命令之前执行一些命令。

Dockerfile中的每个后续运行命令都将位于/目录的上下文中。因此,您的.tar文件不在example/目录中,它实际上应该在/目录中,因为您的“cd to the folder”对于后续的运行命令没有任何意义。在运行wget之前,不要执行cd示例,而要执行WORKDIR示例,例如:


或者,添加cd示例&&。。。在您希望在示例目录中执行的任何命令之前先执行一些命令。

正如Ntokozo所述,每个RUN命令在构建过程中都是一个单独的会话。因此,Docker的真正设计目的是将尽可能多的命令打包到一次运行中,从而允许更小的总体图像大小和更少的层。所以命令可以这样写:

RUN apt-get update && \
    apt-get install -y wget && \
    mkdir -p example && \
    cd example/ && \
    wget -r https://host/file.tar && \
    tar -xvf *.tar && \
    rm -r example/*.tar && \
    mv example/foo example/bar

正如Ntokozo所说,每个RUN命令在构建过程中都是一个单独的会话。因此,Docker的真正设计目的是将尽可能多的命令打包到一次运行中,从而允许更小的总体图像大小和更少的层。所以命令可以这样写:

RUN apt-get update && \
    apt-get install -y wget && \
    mkdir -p example && \
    cd example/ && \
    wget -r https://host/file.tar && \
    tar -xvf *.tar && \
    rm -r example/*.tar && \
    mv example/foo example/bar

小写字母“wget”,然后rm前面的“cd..”:我非常确定最后一行也应该从MV改为“MV”。小写字母“wget”,然后rm前面的“cd..”:我非常确定最后一行也应该从MV改为“MV”。