【问题标题】:How to access Docker Container with Clickhouse in Windows for loading data? [duplicate]如何在 Windows 中使用 Clickhouse 访问 Docker Container 以加载数据? [复制]
【发布时间】:2019-08-04 17:57:02
【问题描述】:

我有兴趣将数据加载到 docker 容器中,clickhouse 目前在 windows docker 桌面上运行。我已经建立了我的表并以 .csv 格式准备了 R 中的数据,但现在想使用系统而不是通过 R 或 Python 加载数据。在 Ubuntu 中,我之前在没有 docker 的情况下使用此博客中的代码加载到我的 clickhouse 数据库中完成了此操作:

https://tech.marksblogg.com/billion-nyc-taxi-clickhouse.html

 time (for filename in /home/mark/trips/trips_x*.csv.gz; do
            gunzip -c $filename | \
                python trans.py | \
                clickhouse-client \
                    --query="INSERT INTO trips FORMAT CSV"
        done)

在访问 docker 容器时,我将如何使用 windows bash 或 powershell 实现类似的过程?现在我在 Windows 中,所以我有 clickhouse dockerized 并在那里运行。

编辑

我的文件是 csv 格式,所以这是我的第一次尝试:

#loop through files
$files = Get-ChildItem "C:\Users\xxxxx\Documents\testing_load"

foreach ($f in $files){
    $outfile = $f.FullName | Write-Host `
    docker run -it --rm --link chanalytics:clickhouse-server yandex/clickhouse-client --host clickhouse-server `
    INSERT INTO trips FORMAT CSV

}

尝试对目录中的每个 csv 文件调用插入命令

【问题讨论】:

  • 您在寻找clickhouse-client 的--host 和--port 选项吗?
  • 如果需要通过 powershell 访问,那么可以。目前clickhouse服务器在我使用--port设置的本地主机的8123上运行。 Clickhouse 客户端可以毫无问题地访问该端口。

标签: powershell docker clickhouse


【解决方案1】:
Figured it out I think:


#loop through files
$files = Get-ChildItem "C:\Users\xxxx\Documents\testing_load"

foreach ($f in $files){
    $outfile = $f.FullName | Write-Host
    Get-Date | Write-Host    
    "Start loading" + $f.FullName | Write-Host
    docker run -it --rm --link chanalytics:clickhouse-server yandex/clickhouse-client --host clickhouse-server clickhouse-client --query="INSERT INTO trips FORMAT CSV"
     Get-Date | Write-Host 
    "End loading" + $f.FullName | Write-Host
}

【讨论】:

  • 正如您链接的后续问题所证明的那样,这无效 - 没有输入被传递给 docker 命令(即使您通过查询解决了问题字符串)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-09
  • 1970-01-01
  • 1970-01-01
  • 2019-12-11
  • 2021-04-17
相关资源
最近更新 更多