Search code examples
clickhouse

Data directory permissions on host for Clickhouse installation via docker


My setup for clickhouse is via docker (https://hub.docker.com/r/yandex/clickhouse-server/~/dockerfile/). Currently, I am running some issues when mounting the data directory (/var/lib/clickhouse) from the container to the host machine as I want to persist the data outside of the container runtime.

Since the docker process is responsible for creating the directories on the host (these directories for /var/lib/clickhouse do not exist until running docker with a -v flag), what are the permissions and/or directory structure I should provision on my host instance?

I am bumping into something like:Application: Access to file denied: /var/lib/clickhouse/data. My explicit file mounts are: /var/lib/clickhouse and /var/lib/clickhouse/tmp as prescribed in the configuration file. But since the clickhouse server process seems to create more directories, the docker process is being "rejected" when trying to create more processes.

I could explicitly mount the /data, etc but this makes an assumption that is outside of the configuration. Also, this does work if I give generous permissions top /var/clickhouse like: chmod 777 /var/clickhouse but wanted to make sure this was best practice.


Solution

  • As I see in https://hub.docker.com/r/yandex/clickhouse-server/~/dockerfile/ you can try run on host OS.

    docker run --rm -i --entrypoint /bin/sh yandex/clickhouse-server -c id clickhouse
    

    uid=105(clickhouse) gid=106(clickhouse) groups=106(clickhouse)

    after getting id, you can run on host OS as:

    chown -R 105:106 /var/lib/clickhouse