cucucool
cucucool

Reputation: 3887

Dockerfile - Mount host directory - copy a tar fie and run it - Error

Please find below the docker file contents -

FROM centostaryum
MAINTAINER karthik.jayaraman
VOLUME ["/DockerFiles/Tomcat/tar"]
ADD /tar/apache-tomcat-7.0.47.tar.gz /tmp
RUN ls /tmp
RUN tar -tzf /tmp/apache-tomcat-7.0.47.tar.gz -C /opt
EXPOSE  8080
CMD service tomcat7 start

It gives me the following error

    Step 0 : FROM centostaryum
     ---> 175c30b6dbd7
    Step 1 : MAINTAINER karthik.jayaraman 
     ---> Running in 8872c0c61735
     ---> d16323a6931a
    Removing intermediate container 8872c0c61735
    Step 2 : VOLUME ["/DockerFiles/Tomcat/tar"]
     ---> Running in 829a35f36b3f
     ---> 74314abbc28e
    Removing intermediate container 829a35f36b3f
    Step 3 : ADD /tar/apache-tomcat-7.0.47.tar.gz /tmp
     ---> 07a0bc6713ab
    Removing intermediate container 3af17fba511a
    Step 4 : RUN ls /tmp
     ---> Running in 113ed759c156
    apache-tomcat-7.0.47
     ---> 6fd41ed2fb76
    Removing intermediate container 113ed759c156
    Step 5 : RUN tar -tzf /tmp/apache-tomcat-7.0.47.tar.gz -C /opt
     ---> Running in 08e4d0a1f30a
    tar (child): /tmp/apache-tomcat-7.0.47.tar.gz: Cannot open: 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
    2014/06/13 18:25:32 The command [/bin/sh -c tar -tzf /tmp/apache-tomcat-7.0.47.tar.gz -C /opt] returned a non-
    zero code: 2

The list command from the temp directory in the container lists the tomcat file but i am not sure what is wrong with the tar command.

I would appreciate some help in figuring out this issue. Thanks.

Upvotes: 0

Views: 2896

Answers (2)

zhangjiafeng
zhangjiafeng

Reputation: 11

RUN yum -y update && \ yum -y install wget && \ yum install -y tar.x86_64 && \ yum clean all

Upvotes: 1

Ben Whaley
Ben Whaley

Reputation: 34426

Per the documentation on the ADD command:

If is a local tar archive in a recognized compression format (identity, gzip, bzip2 or xz) then it is unpacked as a directory. Resources from remote URLs are not decompressed. When a directory is copied or unpacked, it has the same behavior as tar -x: the result is the union of:

  • whatever existed at the destination path and
  • the contents of the source tree, with conflicts resolved in favor of "2." on a file-by-file basis.

You can just ADD the file to /opt directly and it will do what you want. More explicitly, just do this:

ADD /tar/apache-tomcat-7.0.47.tar.gz /opt

Upvotes: 1

Related Questions