ADD or COPY a folder in Docker

dockerfile copy directory
docker add vs copy
docker copy . . meaning
docker copy recursive
dockerfile copy wildcard
dockerfile copy multiple directories
copy folder to docker build
docker copy folder and rename

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.

ADD or COPY a folder in Docker, Copy files/folders between a container and the local filesystem The docker cp utility copies the contents of SRC_PATH to the DEST_PATH . You can copy from​  Docker’s official documentation notes that COPY should always be the go-to instruction as it is more transparent than ADD. If you need to copy from the local build context into a container, stick to using COPY. The Docker team also strongly discourages using ADD to download and copy a package from a URL.

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/

docker cp, The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest> . Multiple <src> resource may  COPY and ADD are both Dockerfile instructions that serve similar purposes. They let you copy files from a specific location into a Docker image. COPY takes in a src and destination. It only lets you copy in a local file or directory from your host (the machine building the Docker image) into the Docker image itself.

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/

Docker, It only lets you copy in a local file or directory from your host (the machine building the Docker image) into the Docker image itself. ADD lets you  Unlike the COPY instruction, ADD was part of Docker from the beginning and supports a few additional tricks beyond simply copying files from the build context. The ADD instruction allows you to use a URL as the <src> parameter. When a URL is provided, a file is downloaded from the URL and copied to the <dest>.

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.

Docker Tip #2: The Difference between COPY and ADD in a Dockerfile, In both cases, directories or files (the <src> ) are copied and added to the filesystem of the container at the specified <dest> path. So if both  COPY test relativeDir/ # adds "test" to `WORKDIR`/relativeDir/ COPY test /absoluteDir/ # adds "test" to /absoluteDir/ All new files and directories are created with a UID and GID of 0. Note: If you build using stdin (docker build - < somefile), there is no build context, so COPY can’t be used. COPY obeys the following rules:

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.

Dockerfile: ADD vs COPY, The `WORKDIR` line specifies a new default directory within the image's file system. The COPY and ADD instructions allow you to copy files into your image's​  This will copy a single from the current Docker build context into the image: COPY properties.ini /config/ And this will copy all XML files into the Docker image: COPY *.xml /config/ The main downside of this approach is that we cannot use it for running Docker containers.

WORKDIR, COPY, and ADD Instructions, Description of problem: When using COPY in a Dockerfile and using ADD command does not follow file directory structure when copying  node.js,amazon-web-services,docker. I think the answers regarding the environment variables are good solutions. To offer an alternative, or if you use a file for aws authentication, you could use docker volumes to mount these. Mount a Host Directory as a Data Volume In addition to creating a volume using the -v flag

Dockerfile COPY with file globs will copy files from subdirectories to , COPY — copies local files recursively, given explicit source and destination files or directories. With COPY, you must declare the locations. ADD  FROM creates a layer from the ubuntu:18.04 Docker image. COPY adds files from your Docker client’s current directory. RUN builds your application with make. CMD specifies what command to run within the container. When you run an image and generate a container, you add a new writable layer (the “container layer”) on top of the underlying layers. All changes made to the running container, such as writing new files, modifying existing files, and deleting files, are written to this thin

Docker Copy directory using ADD and COPY commands, How to update/add a file in the Docker Image. The post discusses how to alter a standard docker image pulled from a Public repository in Docker hub as per your need. For the example of this post, we will pull a latest CentOS docker image and add a test directory “test_dir” and create a test file “test_fiel” into it.

Comments
  • Could you please elaborate more your answer adding a little more description about the solution you provide?
  • No Man, It doesn't work. ADD downloads/ /mnt/ But it adds the content of downloads into /mnt/.
  • both your folders source AND destination must end with a /, your try copying also your Dockerfile shows this is correct.
  • Leave the Dockerfile. I just commented what i have tried. It s also not working
  • I am sure this works COPY download/ /tmp/ let me know
  • Just tried COPY src/ /app/ and the content of src gets copied over. This is on docker version 17.03.1-ce