解压缩最简单的Dockerfile:找不到文件

时间:2017-04-12 02:47:46

标签: docker dockerfile tar

我是一个全新的docker用户。我花了很多时间在一个错误上,Dockerfile真的很简单,但是我无法解决这个问题。

我正在尝试下载tar文件,并取消归档

这是我的Dockerfile(每次尝试都不在Dockerfile中,同时我为了简单起见将它们放在一起)

FROM ubuntu:latest

# 1st try
ADD https://download.gnome.org/sources/glib/2.52/glib-2.52.1.tar.xz /tmp/
RUN ls -lah /tmp/glib-2.52.1.tar.xz
ADD /tmp/glib-2.52.1.tar.xz /tmp

# 2nd try
ADD https://download.gnome.org/sources/glib/2.52/glib-2.52.1.tar.xz /tmp/
RUN ls -lah /tmp/glib-2.52.1.tar.xz
RUN tar -C /tmp/ -xf /tmp/glib-2.52.1.tar.xz

# 3rd try
WORKDIR /tmp/
RUN wget https://download.gnome.org/sources/glib/2.52/glib-2.52.1.tar.xz
RUN ls -lah glib-2.52.1.tar.xz
RUN tar -xf glib-2.52.1.tar.xz

# 4th try
RUN wget https://download.gnome.org/sources/glib/2.52/glib-2.52.1.tar.xz -O /tmp/glib-2.52.1.tar.xz
RUN ls -lah /tmp/glib-2.52.1.tar.xz
ADD /tmp/glib-2.52.1.tar.xz /tmp

# 5th try
RUN wget https://download.gnome.org/sources/glib/2.52/glib-2.52.1.tar.xz -O /tmp/glib-2.52.1.tar.xz
RUN ls -lah /tmp/glib-2.52.1.tar.xz
RUN tar -C /tmp/ -xf /tmp/glib-2.52.1.tar.xz

我尝试了所有可能的事情,让这个文件下载并取消归档。

仅在最后一步命令(unarchive,步骤4)上发生错误。

我基本上在我的计算机上尝试了第5次尝试并且它有效:

$> wget https://download.gnome.org/sources/glib/2.52/glib-2.52.1.tar.xz -O /tmp/glib-2.52.1.tar.xz
$> tar -C /tmp/ -xf /tmp/glib-2.52.1.tar.xz
$> ls /tmp/glib*
glib-2.52.1 glib-2.52.1.tar.xz

这是我使用tar时的输出:

$> sudo docker build -t gtk --no-cache .
Sending build context to Docker daemon  3.584kB
Step 1/5 : FROM ubuntu:latest
 ---> 0ef2e08ed3fa
Step 2/5 : ADD https://download.gnome.org/sources/glib/2.52/glib-2.52.1.tar.xz /tmp/
Downloading [==================================================>]  7.676MB/7.676MB
 ---> caa91f90fdca
Removing intermediate container 2952ba563006
Step 3/5 : RUN ls -lah /tmp/glib-2.52.1.tar.xz
 ---> Running in 9570826c1437
-rw------- 1 root root 7.4M Apr  8 06:24 /tmp/glib-2.52.1.tar.xz
 ---> 4335ecb50e2a
Removing intermediate container 9570826c1437
Step 4/5 : RUN tar -C /tmp/ -xf /tmp/glib-2.52.1.tar.xz
 ---> Running in e5a847dd0427
tar (child): xz: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
The command '/bin/sh -c tar -C /tmp/ -xf /tmp/glib-2.52.1.tar.xz' returned a non-zero code: 2

这是我使用ADD时的输出:

[...] # same output

Step 4/5 : ADD /tmp/glib-2.52.1.tar.xz /tmp/
lstat tmp/glib-2.52.1.tar.xz: no such file or directory

感谢您的帮助!

1 个答案:

答案 0 :(得分:7)

请务必仔细阅读输出以获取提示:

tar (child): xz: Cannot exec: No such file or directory

您缺少处理xz档案所需的映像中的xz-utils包。尝试:

RUN apt-get install xz-utils && tar -C /tmp/ -xf /tmp/glib-2.52.1.tar.xz