Install ClickHouse using Docker

### Start server from root[​](#start-server-from-root "Direct link to Start server from root")

Starting the server from root is useful in cases where user namespace is enabled.
To do so run:

```
docker run --rm -e CLICKHOUSE_RUN_AS_ROOT=1 --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 start[​](#how-to-create-default-db-and-user "Direct link to How to create default database and user on start")

Sometimes you may want to create a user (user named `default` is used by default) and database on a container start. You can do it using environment variables `CLICKHOUSE_DB`, `CLICKHOUSE_USER`, `CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT` and `CLICKHOUSE_PASSWORD`:

```
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
```

#### Managing `default` user[​](#managing-default-user "Direct link to managing-default-user")

The user `default` has disabled network access by default in the case none of `CLICKHOUSE_USER`, `CLICKHOUSE_PASSWORD`, or `CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT` are set.

There's a way to make `default` user insecurely available by setting environment variable `CLICKHOUSE_SKIP_USER_SETUP` to 1:

```
docker run --rm -e CLICKHOUSE_SKIP_USER_SETUP=1 -p 9000:9000/tcp clickhouse/clickhouse-server
```

## How to extend this image[​](#how-to-extend-image "Direct link to How to extend this image")

To perform 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.

Note

Scripts under `/docker-entrypoint-initdb.d` are executed in **alphabetical order** by filename. If your scripts have dependencies on each other (for example, a script that creates views must run after the script that creates the referenced tables), ensure your filenames sort in the correct order.

Also, you can provide environment variables `CLICKHOUSE_USER` & `CLICKHOUSE_PASSWORD` that will be used for clickhouse-client during initialization.

For example, to add another user and database, add the following to `/docker-entrypoint-initdb.d/init-db.sh`:

```
#!/bin/bash
set -e

clickhouse client -n <<-EOSQL
    CREATE DATABASE docker;
    CREATE TABLE docker.docker (x Int32) ENGINE = MergeTree
    ORDER BY ();
EOSQL
```

- [Versions](#versions)
  - [Compatibility](#compatibility)- [How to use this image](#how-to-use-image)
    - [Start server instance](#start-server-instance)- [Connect to it from a native client](#connect-to-it-from-native-client)- [Connect to it using curl](#connect-to-it-using-curl)- [Stopping / removing the container](#stopping-removing-container)- [Networking](#networking)- [Volumes](#volumes)- [Linux capabilities](#linear-capabilities)- [Configuration](#configuration)
        - [Start server instance with custom configuration](#start-server-instance-with-custom-config)- [Start server as custom user](#start-server-custom-user)- [Start server from root](#start-server-from-root)- [How to create default database and user on start](#how-to-create-default-db-and-user)- [How to extend this image](#how-to-extend-image)

Was this page helpful?