docker数据拷贝

  docker数据拷贝的方式有很多种,下面介绍几种数据拷贝的方式;此处只是介绍几种简易的方式,更多方式可以google下。

  从容器中向主机拷贝数据

docker cp <containerId>:/file/path/within/container /host/path/target 

docker cp 8e7e5f4574f4:/root/test.txt ./test.txt

  从主机向容器中拷贝数据

docker cp /host/path/target <containerId>:/file/path/within/container

docker cp ./host.txt 8e7e5f4574f4:/root/host.txt

  用-v挂载主机数据卷到容器内

docker run -v /path/to/hostdir:/mnt $container

  其余的在宿主机上操作即可

  通过输入输出符进行拷贝

docker run -i ubuntu /bin/bash -c 'cat > /path/to/container/file' < /path/to/host/file/  

# 或者

docker exec -it <container_id> bash -c 'cat > /path/to/container/file' < /path/to/host/file/
原文地址:https://www.cnblogs.com/rwxwsblog/p/5434767.html