ADD or COPY a folder in Docker

My directory Structure as follows

 Dockerfile downloads

I want to add downloads to /tmp

 ADD downloads /tmp/
 COPY down* /tmp
 ADD ./downloads /tmp

Nothings works. It copies the contents of downloads into tmp. I want to copy the downloads floder. Any idea?

 ADD . tmp/

copies Dockerfile also. i dont want to copy Dockerfile into tmp/


I believe that you need:

COPY downloads/ /tmp/downloads/

That will copy the contents of the downloads directory into a directory called /tmp/downloads/ in the image.


Note: The directory itself is not copied, just its contents

From the dockerfile reference about COPY and ADD, it says Note: The directory itself is not copied, just its contents., so you have to specify a dest directory explicitly.

RE: https://docs.docker.com/engine/reference/builder/#copy

e.g.

Copy the content of the src directory to /some_dir/dest_dir directory.

COPY ./src    /some_dir/dest_dir/

You can use:

RUN mkdir /path/to/your/new/folder/
COPY /host/folder/* /path/to/your/new/folder/

I could not find a way to do it directly with only one COPY call though.


First tar the directory you want to ADD as a single archive file:

tar -zcf download.tar.gz download

Then ADD the archive file in Dockerfile:

ADD download.tar.gz tmp/

The best for me was:

COPY . /tmp/

With following .dockerignore file in root

Dockerfile
.dockerignore
# Other files you don't want to copy

This solution is good if you have many folders and files that you need in container and not so many files that you don't need. Otherwise user2807690' solution is better.