Copy directory to another directory using ADD command?

Better Stack Team
Updated on April 7, 2023

You can copy a directory to another directory using the ADD command in Docker.

The basic syntax of the ADD command is:

 
ADD source destination
  • source: The path to the file or directory you want to copy into the Docker image.
  • destination: The path where you want to copy the file or directory in the Docker image.

To copy a directory from the host machine to a directory in the Docker image, you can use the following ADD command:

 
ADD /path/to/local/directory /path/to/docker/directory

For example, to copy the directory /home/user/myapp from the host machine to the directory /app in the Docker image, you can use the following ADD command:

 
ADD /home/user/myapp /app

This will copy the entire myapp directory and its contents to the /app directory in the Docker image.

Note that the ADD command can also accept URLs as source, so you can also copy files or directories from a remote location. However, it is recommended to use the COPY command instead of ADD for local file copying, as COPY has less functionality than ADD and is therefore safer to use.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack