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.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github