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/

相关文章:

  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2021-06-01
猜你喜欢
  • 2021-06-10
  • 2021-07-20
  • 2022-02-05
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
相关资源
相似解决方案