How do you copy a folder to a Docker container?

To copy a folder into a Docker container, you can use the “docker cp” command in the Docker command line tool.

Here are the steps to copy a folder to a container:

  1. Open the terminal and navigate to the directory where the folder you want to copy is located.
  2. Use the following command to copy the folder into the container:
docker cp <本地文件夹路径> <容器名称或ID>:<容器文件夹路径>

Here, is the local path of the folder to be copied, is the name or ID of the container to copy to, and is the target path of the folder in the container.

To copy the folder /path/to/local/folder from the local directory to the /path/to/container/folder directory in a container named mycontainer, you can run the following command:

docker cp /path/to/local/folder mycontainer:/path/to/container/folder
  1. After running the command, the folder will be copied into the container.

Please note that in order to copy a folder into a running container, you must first stop the container and then copy the folder.

bannerAds