3

I'm trying to run clickhouse-server and clickhouse-client services using Docker and Docker Compose. Based on clickhouse docker-compose file and another compose sample, I created the services in my docker-compose.yml file as you can see below:

docker-compose.yml:

    ch_server:
      container_name: myapp_ch_server
      image: yandex/clickhouse-server
      ports:
        - "8181:8123"
        - "9000:9000"
        - "9009:9009"
      ulimits:
        nproc: 65535
        nofile:
          soft: 262144
          hard: 262144
      volumes: 
        - ./ch_db_data:/var/lib/clickhouse/
        - ./ch_db_logs:/val/log/clickhouse-server/
      networks:
        - myapp-network

    ch_client:
      container_name: myapp_ch_client
      image: yandex/clickhouse-client
      command: ['--host', 'ch_server']
      networks:
        - myapp-network

When I run docker-compose up command, the following exception occurs from clickhouse-client service:

myapp_ch_client | Code: 62. DB::Exception: Empty query
myapp_ch_client exited with code 62

Do you have any idea how to fix this error?

3 Answers 3

4

It just needs to pass the SQL-query in command-params:

version: "2.4"

services:
  ch_server:
    container_name: myapp_ch_server
    image: yandex/clickhouse-server
    ports:
      - "8123:8123"
      - "9000:9000"
      - "9009:9009"
    ulimits:
      nproc: 65535
      nofile:
        soft: 262144
        hard: 262144
    volumes: 
      - ./ch_db_data:/var/lib/clickhouse/
      - ./ch_db_logs:/var/log/clickhouse-server/
    networks:
      - myapp-network
    healthcheck:
      test: wget --no-verbose --tries=1 --spider localhost:8123/ping || exit 1
      interval: 2s
      timeout: 2s
      retries: 16

  ch_client:
    container_name: myapp_ch_client
    image: yandex/clickhouse-client
    command: ['--host', 'ch_server', '--query', 'select * from system.functions order by name limit 4']
    networks:
      - myapp-network
    depends_on:
      ch_server:
        condition: service_healthy

networks:
    myapp-network:

It doesn't make sense to define clickhouse-client in docker-compose. clickhouse-client usually run outside of docker-compose file:

  1. define docker-compose that defines servers (such as ClickHouse (nodes of cluster), Zookeeper, Apache Kafka, etc). For example, let's consider the config with one node of ClickHouse:
version: "2.4"

services:
  ch_server:
    container_name: myapp_ch_server
    image: yandex/clickhouse-server
    ports:
      - "8123:8123"
      - "9000:9000"
      - "9009:9009"
    ulimits:
      nproc: 65535
      nofile:
        soft: 262144
        hard: 262144
    volumes: 
      - ./ch_db_data:/var/lib/clickhouse/
      - ./ch_db_logs:/var/log/clickhouse-server/
    networks:
      - myapp-network
    healthcheck:
      test: wget --no-verbose --tries=1 --spider localhost:8123/ping || exit 1
      interval: 2s
      timeout: 2s
      retries: 16

networks:
    myapp-network:

  1. in the separate terminal run clickhouse-client
cd _folder_where_docker-compose_located

docker-compose exec ch_server clickhouse-client
Sign up to request clarification or add additional context in comments.

Comments

1

2021 version as this tutorial https://dev.to/titronium/clickhouse-server-in-1-minute-with-docker-4gf2

  clickhouse-client:
    image: yandex/clickhouse-client:latest
    depends_on:
      - clickhouse-server
    links:
      - clickhouse-server
    entrypoint:
      - /bin/sleep
    command:
      - infinity

the last line command: - infinity mean it will wait you there forever to connect

Comments

0

Actually, you have access to a ClickHouse client on the command line of the ClickHouse server.

You can easily connect to your server container and call

clickhuse-client

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.