有史以来最简单的 Dockerfile 解压:找不到文件
Simpliest Dockerfile ever to untar: file not found
我是新 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
我已尽一切可能使该文件被下载并取消存档。
错误仅发生在最后一步命令(解压缩,第 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
感谢您的帮助!
始终仔细阅读输出以获取提示:
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
我是新 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
我已尽一切可能使该文件被下载并取消存档。
错误仅发生在最后一步命令(解压缩,第 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
感谢您的帮助!
始终仔细阅读输出以获取提示:
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