Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy directory to another directory using ADD command

Tags:

docker

I have read http://docs.docker.com/engine/reference/builder/#add however I met a problem. I want to copy the local directory go to docker /user/local/

I tried:

ADD go /usr/local/ 

and:

ADD /go/ /usr/local/  

also:

RUN chmod 0755 /usr/local/go/src/make.bash 

However, I see the following error message:

/usr/local/go/src/make.bash: No such file or directory 

but the local go directory does contain make.bash.

like image 371
pengwang Avatar asked Oct 22 '14 09:10

pengwang


People also ask

How do you copy a directory to another directory in Windows command prompt?

Type "xcopy", "source", "destination" /t /e in the Command Prompt window. Instead of “ source ,” type the path of the folder hierarchy you want to copy. Instead of “ destination ,” enter the path where you want to store the copied folder structure. Press “Enter” on your keyboard.

What is the command to copy a directory?

Copying Directories with cp Command To copy a directory, including all its files and subdirectories, use the -R or -r option.

How do I copy a directory from one directory to another in Linux?

In order to copy a directory on Linux, you have to execute the “cp” command with the “-R” option for recursive and specify the source and destination directories to be copied.


2 Answers

ADD go /usr/local/ 

will copy the contents of your local go directory in the /usr/local/ directory of your docker image.

To copy the go directory itself in /usr/local/ use:

ADD go /usr/local/go 

or

COPY go /usr/local/go 
like image 103
Thomasleveil Avatar answered Sep 22 '22 17:09

Thomasleveil


Indeed ADD go /usr/local/ will add content of go folder and not the folder itself, you can use Thomasleveil solution or if that did not work for some reason you can change WORKDIR to /usr/local/ then add your directory to it like:

WORKDIR /usr/local/ COPY go go/ 

or

WORKDIR /usr/local/go COPY go ./ 

But if you want to add multiple folders, it will be annoying to add them like that, the only solution for now as I see it from my current issue is using COPY . . and exclude all unwanted directories and files in .dockerignore, let's say I got folders and files:

- src  - tmp  - dist  - assets  - go  - justforfun  - node_modules  - scripts  - .dockerignore  - Dockerfile  - headache.lock  - package.json  

and I want to add src assets package.json justforfun go so:

in Dockerfile:

FROM galaxy:latest  WORKDIR /usr/local/ COPY . . 

in .dockerignore file:

node_modules headache.lock tmp dist 

In this way, you ignore node_modules headache.lock tmp dist so they will not be added!

Or for more fun (or you like to confuse more people make them suffer as well :P) can be:

* !src  !assets  !go  !justforfun  !scripts  !package.json  

In this way you ignore everything, but exclude what you want to be copied or added only from the "ignore list".

It is a late answer but adding more ways to do the same covers even more cases.

like image 34
Al-Mothafar Avatar answered Sep 23 '22 17:09

Al-Mothafar