In my Dockerfile I've got :

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

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

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

Does somebody know why and how to do it correctly?

asked Jul 2 '14 at 17:24
Anthony O.

3,5103365
 

3 Answers

Unfortunately, (for practical and security reasons I guess), if you want to add/copy local content, it must be located under 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 an option (-f) to set the path of your Dockerfile ; it can be used to achieve what you want, see @Boedy 's response nelow.

answered Jul 2 '14 at 20:01
mbarthelemy

5,56512228
 
5  
Is there a "clean" workaround for this? I'd rather not restructure my whole project directory just to accommodate this. – ben_frankly Nov 21 '14 at 18:35
    
As said by @Günter, there is a workaround here superuser.com/a/842690/136024 ... is it really "clean"? Well at least it's a "workaround" :) – Anthony O. Dec 2 '14 at 8:39
    
See better answer from @Boedy stackoverflow.com/a/34300129/2950621 – nmgeek Jun 19 at 19:27

You can build the Dockerfile from the parent directory:

  1. docker build -t <some tag> -f <dir/dir/Dockerfile> .
answered Dec 15 '15 at 21:54
Boedy

388515
 
    
Worked smoothly ;) – Souciance Eqdam Rashti Mar 2 at 10:51
    
Thank you! This works fine on a local box, but Docker Hub fails to build the image since it tries to do it from its same directory (tbh, just what one would normally expect). Is there any way to do the same trick in Docker Hub? – Marcel Hernandez Mar 25 at 20:31
    
Not that I know of. You could push the image to the registry instead of using automated build. – Boedy Mar 29 at 9:15 
1  
This should be marked as the right answer – Courtland Caldwell Jun 15 at 19:09

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

  1. #docker-composer.yml
  2. foo:
  3. build: foo
  4. volumes:
  5. - ./:/src/:ro

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

Docker: adding a file from a parent directory的更多相关文章

  1. go.mod file not found in current directory or any parent directory; see 'go help modules'

    go的环境设置问题,执行 go env -w GO111MODULE=auto 我的环境:Windows 7, Go 1.17 D:\Apps\GOPATH\src\code.oldboyedu.co ...

  2. C#文件与流(FileStream、StreamWriter 、StreamReader 、File、FileInfo、Directory、directoryInfo、Path、Encoding)

    (FileStream.StreamWriter .StreamReader .File.FileInfo.Directory.DirectoryInfo.Path.Encoding)     C#文 ...

  3. mac brew 安装php扩展报错:parent directory is world writable but not sticky

    $ brew install php70-mcrypt 报错: Error: parent directory is world writable but not sticky 搜索到github的答 ...

  4. Adding AirDrop File Sharing Feature to Your iOS Apps

    http://www.appcoda.com/ios7-airdrop-programming-tutorial/ Adding AirDrop File Sharing Feature to You ...

  5. 使用File、Path和Directory进行常见的操作

    我们偶尔会用到文件操作,其中File.Path和Directory这三个类是比较常见的,今天写了一个测试demo,也是顺便学习一下,记录一二. BTW,使用这几个类的时候需要引用using Syste ...

  6. Error: parent directory is world writable but not sticky

    在本地安装pyenv的时候,出现了如下的报错: ➜ brew install pyenv ==> Downloading https://github.com/yyuu/pyenv/archiv ...

  7. The directory '/home/stone/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If execu

    使用sudo pip install ......的时候出现下面一段黄色的代码: The directory '/home/stone/.cache/pip/http' or its parent d ...

  8. docker :no such file or directory

    ---恢复内容开始--- 其中最主要的问题是:details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: ...

  9. C#回顾 - 2.NET的IO:Path、File、FileInfo、Directory、DirectoryInfo、DriveInfo、FileSystemWatcher

        1.管理文件系统 一般而言,应用程序都会有保存数据.检索数据的需求. 1.1 使用 path 类来访问文件路径 [path常用的方法]:http://www.cnblogs.com/tangg ...

随机推荐

  1. IOS 多线程03-GCD

    如果在本文之前要了解一下线程的基本知识,请访问下面的网址:http://www.cnblogs.com/alunchen/p/5337608.html 1.简介 GCD不仅适用于Object-C,也适 ...

  2. Atitit 视频编码与动画原理attilax总结

    Atitit 视频编码与动画原理attilax总结 1.1. 第一步:实现有损图像压缩和解压1 1.2. 接着将其量化,所谓量化,就是信号采样的步长,1 1.3. 第二步:实现宏块误差计算2 1.4. ...

  3. salesforce 零基础开发入门学习(二)变量基础知识,集合,表达式,流程控制语句

    salesforce如果简单的说可以大概分成两个部分:Apex,VisualForce Page. 其中Apex语言和java很多的语法类似,今天总结的是一些简单的Apex的变量等知识. 有如下几种常 ...

  4. WPF入门教程系列十一——依赖属性(一)

    一.依赖属性基本介绍 本篇开始学习WPF的另一个重要内容依赖属性. 大家都知道WPF带来了很多新的特性,其中一个就是引入了一种新的属性机制——依赖属性.依赖属性出现的目的是用来实现WPF中的样式.自动 ...

  5. 使用maven下载jar包的source和javadoc

    使用maven菜单下载sources和javadocs没什么反应,还是命令给力. 使用参数下载源码包与doc包: -DdownloadSources=true 下载源代码jar -DdownloadJ ...

  6. Html与CSS快速入门01-基础概念

    Web前端技术一直是自己的薄弱环节,经常为了调节一个简单的样式花费大量的时间.最近趁着在做前端部分的开发,果断把这部分知识成体系的恶补一下.内容相对都比较简单,很类似工具手册的学习,但目标是熟练掌握. ...

  7. 深入理解PHP内核(十一)函数-函数的内部结构

    原文链接:http://www.orlion.ga/330/ php的函数包括用户定义的函数.内部函数(print_r count…).匿名函数.变量函数($func = 'print_r'; $fu ...

  8. JSP网站开发基础总结《六》

    对于本篇需要总结的内容,量估计有点大,大家好好看哈,绝对全是干货,代码的已经运行测试,不存在问题,大家可以参考学习,下面开始本篇的内容. 1.添加数据到数据库: 如何用户在JSP页面的填写的信息输入到 ...

  9. Cocos2d-x 3.2 学习笔记(十二)TimberMan!疯狂伐木工!

    学习cocos2dx有一段时间了,试着做了2048游戏,最近又发现个经典游戏,啥也不说果断开工做自己的游戏——TimberMan! 首先说明:游戏资源摘自同类游戏,感谢这些游戏的资源让我完成自己的开发 ...

  10. c#用socket异步传输字符串

    再次特别感谢张子阳老师的文章,是我深感益处. 在前一篇文章中可以看到,尽管消息分成了三条单独发送,但是服务端却将后两条合并成了一条.对于这些情况,我们可以这样处理:就好像HTTP协议一样,在实际的请求 ...