Docker:adding a file from a parent directory

Source: Internet
Author: User

17down votefavorite4

In my Dockerfile I ' ve got:

ADD ../../myapp.war /opt/tomcat7/webapps/

That file exists as ls ../../myapp.war returns me the correct file and when I execute sudo docker build -t myapp . i ' ve got:

Step 1 : ADD ../../myapp.war /opt/tomcat7/webapps/2014/07/02 19:18:09 ../../myapp.war: no such file or directory

Does Somebody know why and what do it correctly?

Docker
shareimprove this question asked Jul 2 ' in 17:24 Anthony o.3,510 33< Span class= "Badge3" >65
1
Some Workarounds Superuser.com/questions/842642–günter zöchbauer Nov at 19:51
Add a Comment
3 answersactiveoldestvotes
Up vote21down voteaccepted

Unfortunately, (for practical and security reasons I guess), if you want to add/copy local content, it must be located und Er the same root path than the Dockerfile .

From the Documentation:

The <src> path must be inside the context of the build; You cannot ADD: /something/something, because the first step of a Docker build is to send the context directory (and subdirectories) To the Docker daemon.

EDIT: There ' s now a option ( -f ) to set the path of your Dockerfile; it can is used to achieve what's want, see @Boedy ' s Response Nelow.

ShareImprove this answer Edited June at 12:45 answered Jul 2 ' at 20:01mbarthelemy5,5651
is there a "clean" Workar Ound for this? I ' d rather not restructure my whole project directory just to accommodate This. – ben_frankly nov" at 18:35
As said by @günter, there are a workaround here superuser.com/a/842690/136024 ... is it really "clean"? Well at least it ' s a "workaround":) –anthony O Dec 2 ' in 8:39
See better answer from @Boedy stackoverflow.com/a/34300129/2950621–nmgeek June at 19:27
Add a Comment
Up vote8down vote

You can build the Dockerfile from the parent directory:

docker build -t <some tag> -f <dir/dir/Dockerfile> .
ShareImprove this answer answered Dec ' at 21:54boedy3885
Worked smoothly;) –souciance Eqdam Rashti Mar 2 at 10:51
Thank you! This works fine in a local box, but Docker Hub fails to build the image since it tries to does it from its same directory (t BH, just what one would normally expect). Is there any-to-do the same-trick in Docker Hub? –marcel Hernandez Mar at 20:31
Not that I know of. You could push the image to the registry instead of using automated build. –boedy Mar at 9:15
1
This should is marked as the right Answer–courtland Caldwell June at 19:09
Add a Comment
Up vote0down vote

The solution for those who use composer are to use a volume pointing to the parent folder:

#docker-composer.ymlfoo:  build: foo  volumes:    - ./:/src/:ro

But I ' m pretty sure the can is done playing with volumes in Dockerfile.

ShareImprove this answer

Docker:adding a file from a parent directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.