ADD or COPY 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 

Powered by Nothings. It copies the contents of the downloads to tmp. I want to copy the loader floder. Any idea?

  ADD . tmp/ 

copies the Dockerfile. I do not want to copy Dockerfile to tmp /

+12
docker
source share
6 answers

I believe that you need:

 COPY downloads /tmp/downloads/ 

This will copy the contents of the download directory to a directory named /tmp/downloads/ .

+22
source share

Note: the directory itself is not copied, only its contents

Note from the dockerfile help about COPY and ADD Note: The directory itself is not copied, just its contents. so you must explicitly specify the dest directory.

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

eg

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

 COPY ./src /some_dir/dest_dir/ 
+3
source share

First enter the directory that you want to add as a single archive file:

 tar -zcf download.tar.gz download 

Then add the archive file to the Docker file:

 ADD download.tar.gz tmp/ 
+1
source share

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 this directly with just one COPY call.

0
source share

Best for me was:

 COPY . /tmp/ 

With the following .dockerignore file in the 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 the container, and not many files that you do not need. Otherwise, user2807690 'solution is better.

0
source share

If the folder does not end with / , it is considered a file, so you should write something like the ADD /abc/ def/ entry if you want to copy the folder.

-one
source share

All Articles