|
| 1 | +# ClickHouse Server Docker Image |
| 2 | + |
| 3 | +## What is ClickHouse? |
| 4 | + |
| 5 | +%%LOGO%% |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | +For more information and documentation see https://clickhouse.com/. |
| 12 | + |
| 13 | +## Versions |
| 14 | + |
| 15 | +- The `latest` tag points to the latest release of the latest stable branch. |
| 16 | +- Branch tags like `22.2` point to the latest release of the corresponding branch. |
| 17 | +- Full version tags like `22.2.3.5` point to the corresponding release. |
| 18 | +- The tag `head` is built from the latest commit to the default branch. |
| 19 | +- Each tag has optional `-alpine` suffix to reflect that it's built on top of `alpine`. |
| 20 | + |
| 21 | +### Compatibility |
| 22 | + |
| 23 | +- The amd64 image requires support for [SSE3 instructions](https://en.wikipedia.org/wiki/SSE3). Virtually all x86 CPUs after 2005 support SSE3. |
| 24 | +- The arm64 image requires support for the [ARMv8.2-A architecture](https://en.wikipedia.org/wiki/AArch64#ARMv8.2-A) and additionally the Load-Acquire RCpc register. The register is optional in version ARMv8.2-A and mandatory in [ARMv8.3-A](https://en.wikipedia.org/wiki/AArch64#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). |
| 25 | + |
| 26 | +## How to use this image |
| 27 | + |
| 28 | +### start server instance |
| 29 | + |
| 30 | +```bash |
| 31 | +docker run -d --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server |
| 32 | +``` |
| 33 | + |
| 34 | +By default, ClickHouse will be accessible only via the Docker network. See the [networking section below](#networking). |
| 35 | + |
| 36 | +By default, starting above server instance will be run as the `default` user without password. |
| 37 | + |
| 38 | +### connect to it from a native client |
| 39 | + |
| 40 | +```bash |
| 41 | +docker run -it --rm --link some-clickhouse-server:clickhouse-server --entrypoint clickhouse-client clickhouse/clickhouse-server --host clickhouse-server |
| 42 | +# OR |
| 43 | +docker exec -it some-clickhouse-server clickhouse-client |
| 44 | +``` |
| 45 | + |
| 46 | +More information about the [ClickHouse client](https://clickhouse.com/docs/en/interfaces/cli/). |
| 47 | + |
| 48 | +### connect to it using curl |
| 49 | + |
| 50 | +```bash |
| 51 | +echo "SELECT 'Hello, ClickHouse!'" | docker run -i --rm --link some-clickhouse-server:clickhouse-server curlimages/curl 'http://clickhouse-server:8123/?query=' -s --data-binary @- |
| 52 | +``` |
| 53 | + |
| 54 | +More information about the [ClickHouse HTTP Interface](https://clickhouse.com/docs/en/interfaces/http/). |
| 55 | + |
| 56 | +### stopping / removing the container |
| 57 | + |
| 58 | +```bash |
| 59 | +docker stop some-clickhouse-server |
| 60 | +docker rm some-clickhouse-server |
| 61 | +``` |
| 62 | + |
| 63 | +### networking |
| 64 | + |
| 65 | +You can expose your ClickHouse running in docker by [mapping a particular port](https://docs.docker.com/config/containers/container-networking/) from inside the container using host ports: |
| 66 | + |
| 67 | +```bash |
| 68 | +docker run -d -p 18123:8123 -p19000:9000 --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server |
| 69 | +echo 'SELECT version()' | curl 'http://localhost:18123/' --data-binary @- |
| 70 | +``` |
| 71 | + |
| 72 | +`22.6.3.35` |
| 73 | + |
| 74 | +or by allowing the container to use [host ports directly](https://docs.docker.com/network/host/) using `--network=host` (also allows achieving better network performance): |
| 75 | + |
| 76 | +```bash |
| 77 | +docker run -d --network=host --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server |
| 78 | +echo 'SELECT version()' | curl 'http://localhost:8123/' --data-binary @- |
| 79 | +``` |
| 80 | + |
| 81 | +`22.6.3.35` |
| 82 | + |
| 83 | +### Volumes |
| 84 | + |
| 85 | +Typically you may want to mount the following folders inside your container to achieve persistency: |
| 86 | + |
| 87 | +- `/var/lib/clickhouse/` - main folder where ClickHouse stores the data |
| 88 | +- `/var/log/clickhouse-server/` - logs |
| 89 | + |
| 90 | +```bash |
| 91 | +docker run -d \ |
| 92 | + -v $(realpath ./ch_data):/var/lib/clickhouse/ \ |
| 93 | + -v $(realpath ./ch_logs):/var/log/clickhouse-server/ \ |
| 94 | + --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server |
| 95 | +``` |
| 96 | + |
| 97 | +You may also want to mount: |
| 98 | + |
| 99 | +- `/etc/clickhouse-server/config.d/*.xml` - files with server configuration adjustments |
| 100 | +- `/etc/clickhouse-server/users.d/*.xml` - files with user settings adjustments |
| 101 | +- `/docker-entrypoint-initdb.d/` - folder with database initialization scripts (see below). |
| 102 | + |
| 103 | +### Linux capabilities |
| 104 | + |
| 105 | +ClickHouse has some advanced functionality, which requires enabling several [Linux capabilities](https://man7.org/linux/man-pages/man7/capabilities.7.html). |
| 106 | + |
| 107 | +They are optional and can be enabled using the following [docker command-line arguments](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities): |
| 108 | + |
| 109 | +```bash |
| 110 | +docker run -d \ |
| 111 | + --cap-add=SYS_NICE --cap-add=NET_ADMIN --cap-add=IPC_LOCK \ |
| 112 | + --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server |
| 113 | +``` |
| 114 | + |
| 115 | +## Configuration |
| 116 | + |
| 117 | +The container exposes port 8123 for the [HTTP interface](https://clickhouse.com/docs/en/interfaces/http_interface/) and port 9000 for the [native client](https://clickhouse.com/docs/en/interfaces/tcp/). |
| 118 | + |
| 119 | +ClickHouse configuration is represented with a file "config.xml" ([documentation](https://clickhouse.com/docs/en/operations/configuration_files/)) |
| 120 | + |
| 121 | +### Start server instance with custom configuration |
| 122 | + |
| 123 | +```bash |
| 124 | +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 |
| 125 | +``` |
| 126 | + |
| 127 | +### Start server as custom user |
| 128 | + |
| 129 | +```bash |
| 130 | +# $(pwd)/data/clickhouse should exist and be owned by current user |
| 131 | +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 |
| 132 | +``` |
| 133 | + |
| 134 | +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. |
| 135 | + |
| 136 | +### Start server from root (useful in case of enabled user namespace) |
| 137 | + |
| 138 | +```bash |
| 139 | +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 |
| 140 | +``` |
| 141 | + |
| 142 | +### How to create default database and user on starting |
| 143 | + |
| 144 | +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`: |
| 145 | + |
| 146 | +```bash |
| 147 | +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 |
| 148 | +``` |
| 149 | + |
| 150 | +## How to extend this image |
| 151 | + |
| 152 | +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. |
| 153 | +Also, you can provide environment variables `CLICKHOUSE_USER` & `CLICKHOUSE_PASSWORD` that will be used for clickhouse-client during initialization. |
| 154 | + |
| 155 | +For example, to add an additional user and database, add the following to `/docker-entrypoint-initdb.d/init-db.sh`: |
| 156 | + |
| 157 | +```bash |
| 158 | +#!/bin/bash |
| 159 | +set -e |
| 160 | + |
| 161 | +clickhouse client -n <<-EOSQL |
| 162 | + CREATE DATABASE docker; |
| 163 | + CREATE TABLE docker.docker (x Int32) ENGINE = Log; |
| 164 | +EOSQL |
| 165 | +``` |
0 commit comments