Docker中执行tar: Cannot read: Is a directory in docker

我想要在Docker镜像中安装Hadoop,下面是Dockerfile的一部分:

COPY hadoop-3.1.2.tar.gz /usr/hadoop/hadoop-3.1.2.tar.gz
RUN cd /usr/hadoop && ls && tar -xzvf hadoop-3.1.2.tar.gz && rm -f hadoop-3.1.2.tar.gz

然后通过docker build构建镜像时抛出如下错误:

tar: /hadoop-3.1.2.tar.gz: Cannot read: Is a directory
tar: At beginning of tape, quitting now
tar: Error is not recoverable: exiting now

原因是ADD命令会自动把压缩文件进行解压缩,无需自己解压缩,所以会提示“文件已存在”。如果想要自己进行解压缩,需要将ADD换成COPY

你可能感兴趣的:(Docker中执行tar: Cannot read: Is a directory in docker)