How Do You Copy Many Files from Your Linux Server into a Docker Container?

Problem scenario
You want to move copies of all the files in a given subdirectory (we'll say /tmp/a/ for an example) on a Docker host to go into a Docker container.  

From the server use the command "docker ps" to find the container ID.  Now that you have the container ID, you can write a script to move copies of the files into the Docker container.  Write this Bash script (with its final word being "done"):

fir="docker cp "
las=" d387209ce13:/tmp/cont/"

for filename in /tmp/a/*; do
           eval $full

Use this command: chmod u+x
Change the "d387209ce13" your the container ID.  Change the /tmp/cont/ to the desired destination directory path in the Docker container. Run it (e.g., ./ in the directory on the Docker host that has all the files you want copied (the location of the source files).  For future reference, the eval command is very useful.  Shell scripts can compose complex bash expressions and ultimately execute them easily with the eval command.

Leave a comment

Your email address will not be published. Required fields are marked *