Docker删除下载的文件

时间:2014-09-27 21:10:34

标签: download docker boot2docker

我正在尝试设置Docker容器来测试Magento扩展。我期望用这样的Dockerfile做到这一点:

FROM php:5.4-apache
WORKDIR /var/www/html
ADD http://www.magentocommerce.com/downloads/assets/1.9.0.1/magento-1.9.0.1.tar.gz /var/www/html
# Other installation steps

但那失败了:

2014/09/27 17:03:25 lchown /mnt/sda1/var/lib/docker/aufs/mnt/d5ced8f20d760458093f2993ea25ffa9a644c93d5b134e793f820f53dfc2d70d/var/www/html/tmp: not a directory

我认为它与我在OS X上使用boot2docker有关。(我记得OS X有一些文件系统与Docker共享问题。)所以我再次尝试使用这个Dockerfile:

FROM php:5.4-apache
WORKDIR /var/www/html
# We should be able to use ADD to fetch a remote file, but
# something is causing that to fail (OS X Docker limitations, I guess?)
RUN ["/usr/bin/curl", "-O", "http://www.magentocommerce.com/downloads/assets/1.9.0.1/magento-1.9.0.1.tar.gz"]
RUN ["/bin/tar", "-xzf", "magento-1.9.0.1.tar.gz"]
# Other installation steps

当我运行上面的命令时,curl执行得很好并且没有错误地退出,但是生成的容器不包含下载的文件,因此下游tar命令失败。

Step 2 : RUN ["/usr/bin/curl", "-O", "http://www.magentocommerce.com/downloads/assets/1.9.0.1/magento-1.9.0.1.tar.gz"]
 ---> Running in 2695c5e95f77
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21.9M  100 21.9M    0     0   817k      0  0:00:27  0:00:27 --:--:--  842k
 ---> bb716a60c4ef
Removing intermediate container 2695c5e95f77
Step 3 : RUN ["/bin/tar", "-xzf", "magento-1.9.0.1.tar.gz"]
 ---> Running in 95cc533947c1
tar (child): magento-1.9.0.1.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
/bin/tar: Child returned status 2
/bin/tar: Error is not recoverable: exiting now
2014/09/27 17:07:47 The command [/bin/tar -xzf magento-1.9.0.1.tar.gz] returned a non-zero code: 2

如果我检查中间容器,那么文件确实不存在。

$ docker run bb716a60c4ef /bin/sh -c 'pwd && ls -al'
/var/www/html
total 8
drwxr-xr-x 2 www-data www-data 4096 Sep 27 21:09 .
drwxr-xr-x 4 root     root     4096 Sep 23 11:09 ..

那么它去了哪里,我如何设置一个允许我下载和修改文件系统的Dockerfile?

1 个答案:

答案 0 :(得分:3)

这里有几件事需要注意。我将从第一个Dockerfile开始,因为那个的修复非常简单:

FROM php:5.4-apache
WORKDIR /var/www/html
ADD http://www.magentocommerce.com/downloads/assets/1.9.0.1/magento-1.9.0.1.tar.gz /var/www/html/
# Other installation steps
你抓到了吗?将/添加到目标的末尾会告诉ADD命令将其视为文件夹。请参阅https://docs.docker.com/reference/builder/#add处的复制规则的第3个要点。

第二个Dockerfile对我来说有点神秘。但我怀疑它与父图像设置/var/www/html有关,作为跳过图层版本控制的卷。请参阅https://github.com/docker-library/php/blob/master/5.4/apache/Dockerfile#L46