Run Clickhouse server in Docker WSL2. Can't insert records because Permission denied

Hi All!

I use this docker-compose.yml:

services:

clickhouse:

image: clickhouse/clickhouse-server:24.3.5.46   

container_name: clickhouse_24.3.5.46

ulimits:

  nofile:

    soft: 262144

    hard: 262144

network_mode: host

volumes:

  - ./ch_data:/var/lib/clickhouse

  - ./ch_logs:/var/log/clickhouse-server

  # - ./init:/docker-entrypoint-initdb.d

environment:

  # CLICKHOUSE_USER: admin

  # CLICKHOUSE_PASSWORD: "admin"

  CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1 

After insert to table got this error:

DatabaseError: Received ClickHouse exception, code: 1001, server response: std::exception. Code: 1001, type: std::__1::__fs::filesystem::filesystem_error, e.what() = filesystem error: in rename: Permission denied [“/var/lib/clickhouse/store/85d/85d658de-be98-42aa-be59-c66d8dcc565a/tmp_insert_202511_1_1_0/”] [“/var/lib/clickhouse/store/85d/85d658de-be98-42aa-be59-c66d8dcc565a/202511_1_1_0/”]
Cannot print extra info for Poco::Exception (version 24.3.5.46 (official build)) (for url http://localhost:8123)

Please share the output of docker info, to make sure whether you run docker-ce or Docker Desktop.

You do use bind-volumes, thus you must make sure the permissions and/or ownership of the host folders you bind into container folders are correct.

The image description shows how to start the container with arbitrary user and group id:
https://hub.docker.com/r/clickhouse/clickhouse-server/#start-server-as-custom-user

The cli arg -u <uid>:<gid> translates to the service/container property user: <uid>:<gid> in the compose file.

The other approach would be to find out which uid is actually used by the process inside the container, and align the owner of your host folders to uss the same:

> docker run -d --rm --name test clickhouse/clickhouse-server:24.3.5.46
d343030860382553f8fcc997a0b9fdde36daf2f8b80a46047d406721eceea432

> docker exec test ps auxn
    USER     PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
     101       1 35.0  2.5 6530096 417204 ?      Ssl  14:18   0:01 /usr/bin/clickhouse-server --config-file=/etc/clickhouse-server/config.xml
       0     704  0.0  0.0   8896  3168 ?        Rs   14:18   0:00 ps auxn

> docker exec test id 101
uid=101(clickhouse) gid=101(clickhouse) groups=101(clickhouse)

> docker stop test

Now we know that clickhouse is started with uid=101, gid=101. Now you can change the permissions to this owner: chown 101:101 -r ch_data and chown 101:101 -r ch_logs. Note: make sure to be in the folder where the compose file is located, as the chown commands expect you to be in the folder.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.