Tuesday, June 13, 2023

Docker: Copy files between Host(your PC) and Container

Docker File Copy Command: docker cp

The file copy command in Docker is docker cp. This command is used to copy files between the host and the container. In this post, we will help you understand this command through its usage and examples.

Usage of docker cp command

The basic structure of the docker cp command is as follows.

docker cp [options] source_path destination_path
  • source_path is the path of the file or directory.
  • destination_path is the path of the file or directory.

Options of docker cp command

The docker cp command supports the following options.

  • -a: If both the source and destination are directories, it also copies all subdirectories and files.
  • -i: Displays the input prompt.
  • -v: Reads the source and destination from the input without specifying them.

Examples of using the docker cp command

For example, to copy the /path/foo.txt file from the host to the /path/foo.txt file in the container, run the command as follows.

docker cp /path/foo.txt mycontainer:/path/foo.txt

To copy the /path/foo.txt file from the container to the /path/foo.txt file on the host, run the command as follows.

docker cp mycontainer:/path/foo.txt /path/foo.txt

Conclusion

With the docker cp command, you can easily copy files between the host and the container. It is important to familiarize yourself with these basic commands for efficient use of Docker.


0 개의 댓글:

Post a Comment