首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Dockerfile wget失败

Dockerfile wget失败
EN

Stack Overflow用户
提问于 2019-02-16 06:11:48
回答 2查看 9.3K关注 0票数 1

我有以下代码

代码语言:javascript
复制
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

但是我得到了以下错误:

代码语言:javascript
复制
/bin/sh: 1: WGET: not found
tar: example/*.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

我是码头的新手。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-17 00:54:00

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

代码语言:javascript
复制
RUN apt-get update
RUN apt-get install -y wget     #install wget lib
RUN mkdir -p example     # create folder and cd to folder
WORKDIR example/         # change the working directory for subsequent commands
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

或者,在example目录中,在要执行的任何命令之前添加cd example && ... some command

票数 3
EN

Stack Overflow用户

发布于 2019-08-08 05:01:59

正如Ntokozo所说,在构建过程中,每个运行命令都是一个单独的“会话”。因此,Docker实际上被设计为在一次运行中打包尽可能多的命令,从而允许更小的整体图像大小和更少的层。所以命令可以写成这样:

代码语言:javascript
复制
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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54717736

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档