Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"docker cp" all files from a folder to existing container folder

Tags:

docker

Am I missing something when I try to copy files from one folder to a existing container folder:

Doc

I want to copy files within the build(host) folder to html in my container:

docker cp ./src/build b081dbbb679b:/usr/share/nginx/html 

To be clear; I need to copy from host to container.

But it copies the whole build folder and copies it to ..html/build

I just need the files(and sub folders) within the build folder to be copied into ..html.

Am I missing something or do I have to copy each file one by one?

like image 366
Chris G. Avatar asked Sep 14 '15 13:09

Chris G.


People also ask

How do I copy a folder using docker cp?

To copy the target, use the -L option, for example: $ ln -s /tmp/somefile /tmp/somefile. ln $ docker cp -L /tmp/somefile. ln myappcontainer:/tmp/ This command copies content of the local /tmp/somefile into the file /tmp/somefile.


2 Answers

Here is the explanation from the doc on how to use the cp command in docker, which will fix your issue with /. at the end of SRC_PATH:

  • SRC_PATH does not end with /. (that is: slash followed by dot)

    • the source directory is copied into this directory
  • SRC_PATH does end with /. (that is: slash followed by dot)

    • the content of the source directory is copied into this directory
like image 126
BMW Avatar answered Nov 01 '22 00:11

BMW


Copy files/folders between a container and the local filesystem is like below formats:

  • Copy file to folder inside container:

    docker cp ./src/build/index.html ContainerName:/app/ 

    above example shows index.html file is copying to app folder inside container

  • Copy all files to folder inside container:

    docker cp ./src/build/. ContainerName:/app/ 

    above example shows all files inside build folder are copying to app folder inside container

like image 43
Sina Lotfi Avatar answered Nov 01 '22 00:11

Sina Lotfi