ClickHouse container permissions and faster startup

If you’re using ClickHouse via the docker image which is the way we’d usually recommend customers to install it for testing and perhaps even for live deployments, you might have noticed the startup time is a bit slow. A related issue that we saw with some CentOS-based customers is that in the 21.1 release in January the uid/gid of the database files changed, meaning that upgraded containers would sometimes not start. This is all down to the owner/group that the clickhouse-server instance in the container runs as.

Since 21.1 the uid/gid has been forced to 101 (previously it may have been 999 in some situations). To avoid permissions issues, when the container starts up it runs a script prior to starting the clickhouse-server process which changes the ownership on all the data files. For large instances, even on SSDs this can take several minutes.

Our recommendations for customers are to run the ClickHouse server container as follows:

docker run -d \
    --name clickhouse --hostname clickhouse --restart=unless-stopped \
    --ulimit nofile=262144:262144 \
    -e CLICKHOUSE_DO_NOT_CHOWN=1 `# Faster startup` \
    -e CLICKHOUSE_UID=101 -e CLICKHOUSE_GID=101 \
    -p 8123:8123 -p 9000:9000 \
    -v /clickhouse/data:/var/lib/clickhouse \
    -v /clickhouse/logs:/var/log/clickhouse-server \
    -v /clickhouse/config:/etc/clickhouse-server:ro \
    yandex/clickhouse-server:21.2.2.8

On the first run, you probably want to remove the CLICKHOUSE_DO_NOT_CHOWN setting so that default permissions are created for the various volume mounts, but for all subsequent runs you should set this to avoid potentially lengthy startup times.

Leave a Reply

Your email address will not be published. Required fields are marked *