我有以下代码
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我是码头的新手。
发布于 2019-02-17 00:54:00
Dockerfile文件中的每个后续RUN命令都将位于/目录的上下文中。因此,您的.tar文件不在example/目录中,它实际上应该在/目录中,因为您的'cd to the folder‘对后续的RUN命令没有任何意义。与其执行cd example,不如在运行wget之前执行WORKDIR example,例如:
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。
发布于 2019-08-08 05:01:59
正如Ntokozo所说,在构建过程中,每个运行命令都是一个单独的“会话”。因此,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/barhttps://stackoverflow.com/questions/54717736
复制相似问题