ClickHouse/docker/server/README.md

142 lines
7.0 KiB
Markdown
Raw Normal View History

2016-06-16 10:25:05 +00:00
# ClickHouse Server Docker Image
## What is ClickHouse?
ClickHouse is an open-source column-oriented database management system that allows generating analytical data reports in real time.
ClickHouse manages extremely large volumes of data in a stable and sustainable manner. It currently powers [Yandex.Metrica](https://metrica.yandex.com/), worlds [second largest](http://w3techs.com/technologies/overview/traffic_analysis/all) web analytics platform, with over 13 trillion database records and over 20 billion events a day, generating customized reports on-the-fly, directly from non-aggregated data. This system was successfully implemented at [CERNs LHCb experiment](https://www.yandex.com/company/press_center/press_releases/2012/2012-04-10/) to store and process metadata on 10bn events with over 1000 attributes per event registered in 2011.
2021-09-22 00:22:57 +00:00
For more information and documentation see https://clickhouse.com/.
2016-06-16 10:25:05 +00:00
## How to use this image
### start server instance
```bash
2021-09-19 22:52:21 +00:00
$ docker run -d --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
2016-06-16 10:25:05 +00:00
```
2020-12-14 15:50:48 +00:00
By default ClickHouse will be accessible only via docker network. See the [networking section below](#networking).
2016-06-16 10:25:05 +00:00
### connect to it from a native client
```bash
2021-09-19 22:52:21 +00:00
$ docker run -it --rm --link some-clickhouse-server:clickhouse-server clickhouse/clickhouse-client --host clickhouse-server
2016-06-16 10:25:05 +00:00
```
2021-09-22 00:22:57 +00:00
More information about [ClickHouse client](https://clickhouse.com/docs/en/interfaces/cli/).
2016-06-16 10:25:05 +00:00
### connect to it using curl
```bash
2020-12-14 15:50:48 +00:00
echo "SELECT 'Hello, ClickHouse!'" | docker run -i --rm --link some-clickhouse-server:clickhouse-server curlimages/curl 'http://clickhouse-server:8123/?query=' -s --data-binary @-
```
2021-09-22 00:22:57 +00:00
More information about [ClickHouse HTTP Interface](https://clickhouse.com/docs/en/interfaces/http/).
2020-12-14 15:54:37 +00:00
### stopping / removing the containter
2020-12-14 15:50:48 +00:00
```bash
$ docker stop some-clickhouse-server
$ docker rm some-clickhouse-server
```
### networking
You can expose you ClickHouse running in docker by [mapping particular port](https://docs.docker.com/config/containers/container-networking/) from inside container to a host ports:
```bash
2021-09-19 22:52:21 +00:00
$ docker run -d -p 18123:8123 -p19000:9000 --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
2020-12-14 15:50:48 +00:00
$ echo 'SELECT version()' | curl 'http://localhost:18123/' --data-binary @-
20.12.3.3
```
2020-12-14 15:53:58 +00:00
or by allowing container to use [host ports directly](https://docs.docker.com/network/host/) using `--network=host` (also allows archiving better network performance):
2020-12-14 15:50:48 +00:00
```bash
2021-09-19 22:52:21 +00:00
$ docker run -d --network=host --name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
2020-12-14 15:50:48 +00:00
$ echo 'SELECT version()' | curl 'http://localhost:8123/' --data-binary @-
20.12.3.3
```
### Volumes
2020-12-14 15:50:48 +00:00
Typically you may want to mount the following folders inside your container to archieve persistency:
* `/var/lib/clickhouse/` - main folder where ClickHouse stores the data
* `/val/log/clickhouse-server/` - logs
```bash
$ docker run -d \
-v $(realpath ./ch_data):/var/lib/clickhouse/ \
-v $(realpath ./ch_logs):/var/log/clickhouse-server/ \
2021-09-19 22:52:21 +00:00
--name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
2020-12-14 15:50:48 +00:00
```
You may also want to mount:
* `/etc/clickhouse-server/config.d/*.xml` - files with server configuration adjustmenets
* `/etc/clickhouse-server/usert.d/*.xml` - files with use settings adjustmenets
* `/docker-entrypoint-initdb.d/` - folder with database initialization scripts (see below).
### Linux capabilities
2020-12-14 15:50:48 +00:00
2020-12-14 15:53:58 +00:00
ClickHouse has some advanced functionality which requite enabling several [linux capabilities](https://man7.org/linux/man-pages/man7/capabilities.7.html).
2020-12-14 15:50:48 +00:00
It is optional and can be enabled using the following [docker command line agruments](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities):
```bash
$ docker run -d \
--cap-add=SYS_NICE --cap-add=NET_ADMIN --cap-add=IPC_LOCK \
2021-09-19 22:52:21 +00:00
--name some-clickhouse-server --ulimit nofile=262144:262144 clickhouse/clickhouse-server
2020-12-14 15:50:48 +00:00
```
2016-06-16 10:25:05 +00:00
## Configuration
2021-09-22 00:22:57 +00:00
Container exposes 8123 port for [HTTP interface](https://clickhouse.com/docs/en/interfaces/http_interface/) and 9000 port for [native client](https://clickhouse.com/docs/en/interfaces/tcp/).
2016-06-16 10:25:05 +00:00
2021-09-22 00:22:57 +00:00
ClickHouse configuration represented with a file "config.xml" ([documentation](https://clickhouse.com/docs/en/operations/configuration_files/))
2016-06-16 10:25:05 +00:00
### Start server instance with custom configuration
2016-06-16 10:25:05 +00:00
```bash
2021-09-19 22:52:21 +00:00
$ 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
2016-06-16 10:25:05 +00:00
```
### Start server as custom user
```
# $(pwd)/data/clickhouse should exist and be owned by current user
2021-09-19 22:52:21 +00:00
$ 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 mounting local directories inside you probably would like to not mess your directory tree with files owner and permissions. Then you could use `--user` argument. In this case, you should mount every necessary directory (`/var/lib/clickhouse` and `/var/log/clickhouse-server`) inside the container. Otherwise, image will complain and not start.
### Start server from root (useful in case of userns enabled)
```
2021-09-19 22:52:21 +00:00
$ 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 user (user named `default` is used by default) and database on image starting. You can do it using environment variables `CLICKHOUSE_DB`, `CLICKHOUSE_USER`, `CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT` and `CLICKHOUSE_PASSWORD`:
```
2021-09-19 22:52:21 +00:00
$ 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
```
2018-11-28 19:55:34 +00:00
## How to extend this image
If you would like to do 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.
2018-11-28 19:55:34 +00:00
For example, to add an additional user and database, add the following to `/docker-entrypoint-initdb.d/init-db.sh`:
```bash
#!/bin/bash
set -e
clickhouse client -n <<-EOSQL
CREATE DATABASE docker;
CREATE TABLE docker.docker (x Int32) ENGINE = Log;
EOSQL
```
2016-06-16 10:25:05 +00:00
## License
2019-09-23 16:18:19 +00:00
View [license information](https://github.com/ClickHouse/ClickHouse/blob/master/LICENSE) for the software contained in this image.