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

Just use "." (Dot - instead of "*" in Linux) after your file path, it will copy entire files from the folder

docker cp /file/path/* containerId:/filepath/nginx/html/

docker cp /file/path/. containerId:/filepath/nginx/html/

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


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

Tags:

Docker