Copying files from host to Docker container

DevOps

I am trying to build a backup and restore solution for the Docker containers. How can I copy files from the host to the container?

Appreciate the help.

2
Answers

Replies

The cp command works similarly to the SSH SCP command. To copy a single file to your docker container, you can use the cp command in the following way.



docker cp file-name-in-host mycontainer:/file-name



If you want to copy multiple files, just specify the folder in the cp command.



docker cp source-folder/. mycontainer:/destination-folder

 

To copy files from the host to a docker container, you have to set the path of the file location in your localhost. Then set the path of the docker container to the location you want to copy the file to. Use the below copy command in the following way.



sudo docker cp /home/username/folderName/fileName  (containerId):/(destinationLocation)

 
 

If you want to unleash your potential in this competitive field, please visit the DevOps course page for more information, where you can find the DevOps tutorials and DevOps frequently asked interview questions and answers as well.

 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.
To Top