docker cp
命令将容器内的文件复制到主机:
docker cp <container_name_or_id>:/path/to/file/in/container /path/to/destination/on/host
将主机文件复制到容器:
docker cp /path/to/local/file <container_name_or_id>:/path/to/destination/in/container
在运行容器时挂载主机目录:
docker run -v /host/path:/container/path image_name
这样容器内/container/path目录下的文件会实时同步到主机的/host/path目录。
类似于卷挂载,但直接指定主机路径:
docker run --mount type=bind,source=/host/path,target=/container/path image_name
docker export
导出容器文件系统docker export <container_id> > container_fs.tar
docker save
保存镜像docker save -o image.tar image_name
进入容器后使用curl/wget等工具下载:
docker exec -it <container_id> bash
curl -O http://example.com/file
或者直接执行下载命令:
docker exec <container_id> curl -O http://example.com/file
如果容器内运行了SSH服务:
scp user@container_ip:/path/to/file /local/path
在容器内启动HTTP服务(如Python简易服务器):
docker exec <container_id> python3 -m http.server 8000
然后在主机上使用浏览器或wget/curl访问http://container_ip:8000
下载文件。
docker cp
docker export
docker save