ClickHouse/docker/server
2024-03-27 21:05:52 +00:00
..
docker_related_config.xml Change <yandex> to <clickhouse> in configs 2021-09-20 01:38:53 +03:00
Dockerfile Make Dockerfile.ubuntu a default image definition 2022-04-01 11:59:46 +02:00
Dockerfile.alpine Backport #61683 to 24.3: #54767 Remove extraneous volumes in Keeper image 2024-03-27 21:05:52 +00:00
Dockerfile.ubuntu Update version_date.tsv and changelogs after v24.2.2.71-stable 2024-03-15 06:50:44 +00:00
entrypoint.sh Update entrypoint.sh 2024-02-14 11:39:22 -05:00
README.md Update README.md 2023-11-04 16:53:22 +01:00

ClickHouse Server Docker Image

What is ClickHouse?

ClickHouse is an open-source column-oriented DBMS (columnar database management system) for online analytical processing (OLAP) that allows users to generate analytical reports using SQL queries in real-time.

ClickHouse works 100-1000x faster than traditional database management systems, and processes hundreds of millions to over a billion rows and tens of gigabytes of data per server per second. With a widespread user base around the globe, the technology has received praise for its reliability, ease of use, and fault tolerance.

For more information and documentation see https://clickhouse.com/.

Versions

  • The latest tag points to the latest release of the latest stable branch.
  • Branch tags like 22.2 point to the latest release of the corresponding branch.
  • Full version tags like 22.2.3.5 point to the corresponding release.
  • The tag head is built from the latest commit to the default branch.
  • Each tag has optional -alpine suffix to reflect that it's built on top of alpine.

Compatibility

  • The amd64 image requires support for SSE3 instructions. Virtually all x86 CPUs after 2005 support SSE3.
  • The arm64 image requires support for the ARMv8.2-A architecture and additionally the Load-Acquire RCpc register. The register is optional in version ARMv8.2-A and mandatory in ARMv8.3-A. Supported in Graviton >=2, Azure and GCP instances. Examples for unsupported devices are Raspberry Pi 4 (ARMv8.0-A) and Jetson AGX Xavier/Orin (ARMv8.2-A).

How to use this image

start server instance

docker run -d --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server

By default, ClickHouse will be accessible only via the Docker network. See the networking section below.

By default, starting above server instance will be run as the default user without password.

connect to it from a native client

docker run -it --rm --link some-clickhouse-server:clickhouse-server --entrypoint clickhouse-client clickhouse/clickhouse-server --host clickhouse-server
# OR
docker exec -it some-clickhouse-server clickhouse-client

More information about the ClickHouse client.

connect to it using curl

echo "SELECT 'Hello, ClickHouse!'" | docker run -i --rm --link some-clickhouse-server:clickhouse-server curlimages/curl 'http://clickhouse-server:8123/?query=' -s --data-binary @-

More information about the ClickHouse HTTP Interface.

stopping / removing the container

docker stop some-clickhouse-server
docker rm some-clickhouse-server

networking

You can expose your ClickHouse running in docker by mapping a particular port from inside the container using host ports:

docker run -d -p 18123:8123 -p19000:9000 --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
echo 'SELECT version()' | curl 'http://localhost:18123/' --data-binary @-
22.6.3.35

or by allowing the container to use host ports directly using --network=host (also allows achieving better network performance):

docker run -d --network=host --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
echo 'SELECT version()' | curl 'http://localhost:8123/' --data-binary @-
22.6.3.35

Volumes

Typically you may want to mount the following folders inside your container to achieve persistency:

  • /var/lib/clickhouse/ - main folder where ClickHouse stores the data
  • /var/log/clickhouse-server/ - logs
docker run -d \
    -v $(realpath ./ch_data):/var/lib/clickhouse/ \
    -v $(realpath ./ch_logs):/var/log/clickhouse-server/ \
    --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server

You may also want to mount:

  • /etc/clickhouse-server/config.d/*.xml - files with server configuration adjustments
  • /etc/clickhouse-server/users.d/*.xml - files with user settings adjustments
  • /docker-entrypoint-initdb.d/ - folder with database initialization scripts (see below).

Linux capabilities

ClickHouse has some advanced functionality, which requires enabling several Linux capabilities.

They are optional and can be enabled using the following docker command-line arguments:

docker run -d \
    --cap-add=SYS_NICE --cap-add=NET_ADMIN --cap-add=IPC_LOCK \
    --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server

Configuration

The container exposes port 8123 for the HTTP interface and port 9000 for the native client.

ClickHouse configuration is represented with a file "config.xml" (documentation)

Start server instance with custom configuration

docker run -d --name some-clickhouse-server --ulimit nofile=262144:262144 -v /path/to/your/config.xml:/etc/clickhouse-server/config.xml clickhouse/clickhouse-server

Start server as custom user

# $(pwd)/data/clickhouse should exist and be owned by current user
docker run --rm --user ${UID}:${GID} --name some-clickhouse-server --ulimit nofile=262144:262144 -v "$(pwd)/logs/clickhouse:/var/log/clickhouse-server" -v "$(pwd)/data/clickhouse:/var/lib/clickhouse" clickhouse/clickhouse-server

When you use the image with local directories mounted, you probably want to specify the user to maintain the proper file ownership. Use the --user argument and mount /var/lib/clickhouse and /var/log/clickhouse-server inside the container. Otherwise, the image will complain and not start.

Start server from root (useful in case of enabled user namespace)

docker run --rm -e CLICKHOUSE_UID=0 -e CLICKHOUSE_GID=0 --name clickhouse-server-userns -v "$(pwd)/logs/clickhouse:/var/log/clickhouse-server" -v "$(pwd)/data/clickhouse:/var/lib/clickhouse" clickhouse/clickhouse-server

How to create default database and user on starting

Sometimes you may want to create a user (user named default is used by default) and database on a container start. You can do it using environment variables CLICKHOUSE_DB, CLICKHOUSE_USER, CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT and CLICKHOUSE_PASSWORD:

docker run --rm -e CLICKHOUSE_DB=my_database -e CLICKHOUSE_USER=username -e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 -e CLICKHOUSE_PASSWORD=password -p 9000:9000/tcp clickhouse/clickhouse-server

How to extend this image

To perform additional initialization in an image derived from this one, add one or more *.sql, *.sql.gz, or *.sh scripts under /docker-entrypoint-initdb.d. After the entrypoint calls initdb, it will run any *.sql files, run any executable *.sh scripts, and source any non-executable *.sh scripts found in that directory to do further initialization before starting the service. Also, you can provide environment variables CLICKHOUSE_USER & CLICKHOUSE_PASSWORD that will be used for clickhouse-client during initialization.

For example, to add an additional user and database, add the following to /docker-entrypoint-initdb.d/init-db.sh:

#!/bin/bash
set -e

clickhouse client -n <<-EOSQL
    CREATE DATABASE docker;
    CREATE TABLE docker.docker (x Int32) ENGINE = Log;
EOSQL

License

View license information for the software contained in this image.