Docker: adding a file from a parent directory


17down votefavorite

4

In my Dockerfile I‘ve got :

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 :

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 how to do it correctly?

docker


shareimprove this question

asked Jul 2 ‘14 at 17:24

Anthony O.

3,5103365

 

1  

Some workarounds superuser.com/questions/842642 – Günter Zöchbauer Nov 30 ‘14 at 19:51

add a comment

3 Answers

activeoldestvotes


up vote21down voteaccepted

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.


shareimprove this answer

edited Jun 20 at 12:45

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

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 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

add a comment


up vote0down vote

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

#docker-composer.yml

foo:
  build: foo
  volumes:
    - ./:/src/:ro

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


shareimprove this answer
时间: 2024-10-10 00:00:00

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

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

(FileStream.StreamWriter .StreamReader .File.FileInfo.Directory.DirectoryInfo.Path.Encoding) C#文件与流(FileStream.StreamWriter .StreamReader .File.FileInfo.Di,有需要的朋友可以参考下. 文件与流(FileStream.StreamWriter .StreamReader .File.FileInfo.Directory.DirectoryInfo

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

我们偶尔会用到文件操作,其中File.Path和Directory这三个类是比较常见的,今天写了一个测试demo,也是顺便学习一下,记录一二. BTW,使用这几个类的时候需要引用using System.IO命名空间. 1 class Program 2 { 3 static void Main(string[] args) 4 { 5 //ProcessPath(); 6 //ProcessFile(); 7 //ReadFileByByteArray(); 8 //ReadFileByAll

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的答案 https://github.com/Homebrew/legacy-homebrew/issues/40345 原因:/tmp目录权限不对 $ ls -ld /private/tmp 打印出来 /private/tmp 被标黄了 解决办法: $ sudo chmod +t /tmp $ ls

Adding AirDrop File Sharing Feature to Your iOS Apps

http://www.appcoda.com/ios7-airdrop-programming-tutorial/ Adding AirDrop File Sharing Feature to Your iOS Apps october 30, 2013 by simon ng 12 comments AirDrop is Apple’s answer to file and data sharing. Before the debut of iOS 7, users need to rely

(转).NET的IO:Path、File、FileInfo、Directory、DirectoryInfo、DriveInfo、FileSystemWatcher

1.管理文件系统 一般而言,应用程序都会有保存数据.检索数据的需求. 1.1 使用 path 类来访问文件路径 [path常用的方法]:http://www.cnblogs.com/tangge/archive/2012/10/30/2746458.html#a3 1.2 使用 File 和 FileInfo 类访问文件 1.2.1 File 类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 static void Main(string[] args

MongoDB: exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating

启动mongodb遇到的一个问题和解决: 转(http://blog.csdn.net/u012877472/article/details/51001025) sudo chmod -R go+w /data/db or this, which will make the directory owned by you: sudo chown -R $USER /data/db

docker系列之file基本操作

dockerfile基础操作 Dockerfile 是记录了镜像是如何被构建出来的配置文件, 可以被 docker 直接执行以创建一个镜像. 它的样子: FROM ubuntu:14.04 MAINTAINER YS.Zou <> ADD run /root/run ADD sources.list /etc/apt/sources.list ADD id_rsa.pub /tmp/pubkey ADD requirements /root/requirements RUN mkdir -p

Introducing shard translator

Introducing shard translator by Krutika Dhananjay on December 23, 2015 GlusterFS-3.7.0 saw the release of sharding feature, among several others. The feature was tagged as “experimental” as it was still in the initial stages of development back then.

Basic linux command-with detailed sample

Here I will list some parameters which people use very ofen, I will attach the output of the command with one parameters as well. 1.   Create a new user:useradd Parameter: