hernantos
hernantos

Reputation: 23

How to connect to local clickhouse db form container?

I started studying Docker and encountered some problems. I use Ubuntu and have local clickhouse database, also script in container, which suppose to write some data in db:

clickhouse-client --host=127.0.0.1 --port=8123 --password=password --query "INSERT INTO some.table FORMAT CSV"

When i tyring run it, got:

Code: 210. DB::NetException: Connection refused (127.0.0.1:8123)

It's work when i try to connect form DataGrip. Also i run docker with --network="host". What am I doing wrong?

Upvotes: 2

Views: 6430

Answers (3)

Pouya Rezaei
Pouya Rezaei

Reputation: 222

i changed port to native(tcp) port and its works fine

docker exec -it some-clickhouse-server bash
clickhouse-client --host=127.0.0.1 --port=9000

ClickHouse client version 24.1.1.2048 (official build).
Connecting to 127.0.0.1:9000 as user default.
Connected to ClickHouse server version 24.1.1.

Upvotes: 0

vladimir
vladimir

Reputation: 15208

DataGrip connects to ClickHouse using HTTP-endpoint on 8123-port.

ClickHouse client uses TCP-endpoint on port 9000.

It looks like need to publish port 9000:

docker run -d --name ch -p 8123:8123 -p 9000:9000 --ulimit nofile=262144:262144 yandex/clickhouse-server

Upvotes: 1

Denny Crane
Denny Crane

Reputation: 13300

clickhouse-client uses a port 9000 because it works over a native tcp protocol

jdbc uses an http port 8123

You can map ports from contanier to your host system (-p 127.0.0.1:8123:8123):

docker run  -d -p 127.0.0.1:8123:8123 -p 127.0.0.1:9000:9000 --name jdbc-test --ulimit nofile=262144:262144 yandex/clickhouse-server:latest

Upvotes: 3

Related Questions