How can files be copied to a container using Docker?
There are two common ways to use the Docker command-line tool to copy files into a container.
- copying files between a Docker container and the host machine
docker cp <源路径/文件> <容器名称/ID>:<目标路径/文件>
For example, to copy the file example.txt from the host to a container named mycontainer in the /data directory, you can use the following command:
docker cp example.txt mycontainer:/data
- File that contains instructions for building and running a Docker container.
- Duplicate
- Include additional information.
- Please reproduce the following text in English.
- Include
FROM ubuntu:latest
COPY example.txt /data/
In the above example, the Dockerfile uses the COPY instruction to copy the example.txt file from the host to the /data directory in the image.
You can achieve the goal of copying files to a container using any method. The specific method you choose depends on your needs and use case.