> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Configurando as capacidades CAP_IPC_LOCK e CAP_SYS_NICE no Docker

> Saiba como resolver os avisos do Docker sobre as capabilities `CAP_IPC_LOCK` e `CAP_SYS_NICE` ao executar o ClickHouse em um contêiner.

<div id="question">
  ## Pergunta
</div>

Ao executar o ClickHouse no Docker, o Docker reclama da ausência das capacidades `CAP_IPC_LOCK` e `CAP_SYS_NICE` no sistema. Como posso resolver isso?

Veja como são as mensagens de log quando não há a capacidade `CAP_SYS_NICE` ou `CAP_SYS_NICE`:

```bash theme={null}
docker run -d --name clickhouse-server \
    --ulimit nofile=262144:262144 \
    --network clickhouse-net \
    -p 8123:8123 -p 9000:9000 -p 9009:9009 -p 9363:9363 \
    clickhouse/clickhouse-server:23.2
```

```response theme={null}
2023.04.19 08:04:10.022720 [ 1 ] {} <Information> Application: It looks like the process has no CAP_IPC_LOCK capability, binary mlock will be disabled. It could happen due to incorrect ClickHouse package installation. You could resolve the problem manually with 'sudo setcap cap_ipc_lock=+ep /usr/bin/clickhouse'. Note that it will not work on 'nosuid' mounted filesystems.

2023.04.19 08:04:10.065860 [ 1 ] {} <Information> Application: It looks like the process has no CAP_SYS_NICE capability, the setting 'os_thread_priority' will have no effect. It could happen due to incorrect ClickHouse package installation. You could resolve the problem manually with 'sudo setcap cap_sys_nice=+ep /usr/bin/clickhouse'. Note that it will not work on 'nosuid' mounted filesystems.
```

<div id="answer">
  ## Resposta
</div>

1. Adicione dois argumentos `--cap-add` para conceder ao contêiner as capacidades `IPC_LOCK` e `SYS_NICE`:

```bash theme={null}
docker run -d --name clickhouse-server \
   --cap-add=SYS_NICE \
   --cap-add=IPC_LOCK \
   --ulimit nofile=262144:262144 \
   --network clickhouse-net \
   -p 8123:8123 -p 9000:9000 -p 9009:9009 -p 9363:9363 \
   clickhouse/clickhouse-server:23.2
```

2. Verifique se as capacidades estão visíveis no contêiner usando o seguinte comando:

```bash theme={null}
apt-get update > /dev/null && apt-get install -y libcap2-bin > /dev/null && capsh --print
```

A resposta é semelhante a:

```response theme={null}
debconf: delaying package configuration, since apt-utils is not installed
WARNING: libcap needs an update (cap=40 should have a name).
Current: = cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_raw,cap_ipc_lock,cap_sys_chroot,cap_sys_nice,cap_mknod,cap_audit_write,cap_setfcap+ep
Bounding set =cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_net_raw,cap_ipc_lock,cap_sys_chroot,cap_sys_nice,cap_mknod,cap_audit_write,cap_setfcap
Ambient set =
Securebits: 00/0x0/1'b0
 secure-noroot: no (unlocked)
 secure-no-suid-fixup: no (unlocked)
 secure-keep-caps: no (unlocked)
 secure-no-ambient-raise: no (unlocked)
uid=0(root) euid=0(root)
gid=0(root)
groups=0(root)
Guessed mode: UNCERTAIN (0)
```

3. Defina manualmente as duas capacidades do ClickHouse

```bash theme={null}
setcap "cap_ipc_lock=+ep cap_sys_nice=+ep" /usr/bin/clickhouse
```

4. Verifique se as capacidades foram aplicadas.

```bash theme={null}
getcap -v /usr/bin/clickhouse
```

Você verá o seguinte:

```response theme={null}
/usr/bin/clickhouse = cap_ipc_lock,cap_sys_nice+ep
```

5. Reinicie o servidor ClickHouse e as mensagens de log não deverão mais ser exibidas.

<br />

Consulte este [artigo sobre capacidades do Linux](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities) para mais detalhes.
