将数据从主机加载到Dockerconfiguration单元容器

我有一个csv文件在我的主机,我有一个docker虚拟机。 我想从主机上的csvfile upload数据到虚拟机。 我正在使用python的hive_service库连接并进行查询。 然而,我坚持如何把数据放入虚拟机。 例如,下面的脚本连接并能够查询configuration单元,但在第二个查询时失败。 我需要从我的主机上传smpl.txt到docker vm

import sys from hive_service import ThriftHive from hive_service.ttypes import HiveServerException from thrift import Thrift from thrift.transport import TSocket from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol try: print "1111" transport = TSocket.TSocket("192.168.99.100", 10000) transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) print "2222" client = ThriftHive.Client(protocol) transport.open() print "3333" client.execute("CREATE TABLE names (name string, value int) ROW FORMAT DELIMITED FIELDS TERMINATED BY ','") client.execute("LOAD DATA LOCAL INPATH './smpl.txt' OVERWRITE INTO TABLE names") # client.execute("SELECT * FROM orders") # while (1): # row = client.fetchOne() # if (row == None): # break # print row #client.execute("SELECT * FROM r") # print client.fetchAll() print "4444" transport.close() except Thrift.TException, tx: print '%s' % (tx.message) 

如果该文件必须已经在docker虚拟机中,则可以考虑使用docker cp ,它允许将本地文件复制到正在运行的容器中。

使用像pypi/docker-py/这样的库,可以转化为:

 c = docker.Client(base_url='unix://var/run/docker.sock', version='1.12', timeout=10) c.copy(container, resource)