使用python脚本将文件从docker复制到主机系统 [英] copy file from docker to host system using python script

查看:81
本文介绍了使用python脚本将文件从docker复制到主机系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从下面的命令登录到了docker,现在我要从python脚本中将文件从docker复制到主机系统中

I have logged into the docker from the below command, now from the python script i want to copy the file from docker to host system how to do this

      sudo  docker run -ti video:new /bin/bash

     import os
     os.system('cp /tmp/a.txt HOST:/tmp/a.txt') 

推荐答案

映射卷,以便与容器中的主机共享数据.

Map a volume to share data with your host from the container.

docker run -v /tmp/:/tmp/ -ti video:new /bin/bash

然后让您的python脚本将文件复制到容器内部的/tmp 目录中.

Then let your python script copy the file to the /tmp directory inside your container.

 import os
 os.system('cp /path/to/a.txt /tmp/a.txt') 

通过 -v 映射,将文件放置在docker主机上的目录/tmp 中.关闭Docker容器后,文件仍会以/tmp/a.txt 的形式存在于主机上.

Through to the -v mapping, the file is placed on the docker host in the directory /tmp. Once you close your docker container, the file will still exist on the host as /tmp/a.txt.

这篇关于使用python脚本将文件从docker复制到主机系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆