[英]Load data from host machine to docker hive container
I have a csv file in my host machine and I have a docker VM.我的主机中有一个 csv 文件,我有一个 docker VM。 I want to upload the data from the csv file in my host to the VM.
我想将主机中 csv 文件中的数据上传到 VM。 I am using python's hive_service library to connect to and make queries.
我正在使用 python 的 hive_service 库来连接和进行查询。 However, I am stuck as to how to put data into the VM.
但是,我不知道如何将数据放入 VM。 For example the script below connects and is able to query hive but fails at the second query.
例如,下面的脚本连接并能够查询配置单元,但在第二次查询时失败。 I need to upload smpl.txt from my host machine to the docker vm
我需要将 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)
If that file must already be in the docker VM, you can consider using docker cp
, which allows for copying a local file to a running container.如果该文件必须已经在 docker VM 中,您可以考虑使用
docker cp
,它允许将本地文件复制到正在运行的容器。
Using a library like pypi/docker-py/
, that would translate into:使用像
pypi/docker-py/
这样的库,这将转化为:
c = docker.Client(base_url='unix://var/run/docker.sock',
version='1.12', timeout=10)
c.copy(container, resource)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.