Skip to main content
The guide on Docker Hub is reproduced below for convenience. The Docker images available make use of the official ClickHouse deb packages. Docker pull command:

Versions

  • The latest tag points to the latest release of the latest stable branch.
  • Branch tags like 22.2 point to the latest release of the corresponding branch.
  • Full Version tags like 22.2.3 and 22.2.3.5 point to the corresponding release.
  • The tag head is built from the latest commit to the default branch.
  • The tags without a suffix point to the image built FROM scratch: it contains only ClickHouse and the few system files it needs, without a shell, a package manager, or coreutils. See Image without a shell below.
  • Each tag has an optional -ubuntu suffix for the image built on top of ubuntu, with a shell and the usual tools, which runs the shell script entrypoint.sh.
  • Each tag has an optional -alpine suffix to reflect that it’s built on top of alpine.
  • Each tag has an optional -distroless suffix for the image built on top of a distroless base image, which runs as the clickhouse user (uid 101) from the start.

Compatibility

  • The amd64 image requires support for the x86-64-v3 microarchitecture level (AVX2, BMI1, BMI2, F16C, FMA, LZCNT, MOVBE, XSAVE). Virtually all x86 CPUs after 2015 support x86-64-v3.
  • The arm64 image requires support for the ARMv8.2-A architecture and additionally the Load-Acquire RCpc register. The register is optional in version ARMv8.2-A and mandatory in ARMv8.3-A. Supported in Graviton >=2, Azure and GCP instances. Examples for unsupported devices are Raspberry Pi 4 (ARMv8.0-A) and Jetson AGX Xavier/Orin (ARMv8.2-A).
  • Since ClickHouse 24.11 Ubuntu images began using ubuntu:22.04 as its base image. It requires docker version >= 20.10.10 containing patch. As a workaround you could use docker run --security-opt seccomp=unconfined instead, however this has security implications.

How to use this image

Start server instance

By default, ClickHouse will be accessible only via the Docker network. See the networking section below. By default, starting above server instance will be run as the default user without password.

Connect to it from a native client

See ClickHouse client for more information about ClickHouse client.

Connect to it using curl

See ClickHouse HTTP Interface for more information about the HTTP interface.

Stopping / removing the container

Networking

the predefined user default doesn’t have the network access unless the password is set, see “How to create default database and user on starting” and “Managing default user” below
You can expose your ClickHouse running in docker by mapping a particular port from inside the container using host ports:
Or by allowing the container to use host ports directly using --network=host (also allows achieving better network performance):
The user default in the example above is available only for the localhost requests

Volumes

Typically you may want to mount the following folders inside your container to achieve persistency:
  • /var/lib/clickhouse/ - main folder where ClickHouse stores the data
  • /var/log/clickhouse-server/ - logs
You may also want to mount:
  • /etc/clickhouse-server/config.d/*.xml - files with server configuration adjustments
  • /etc/clickhouse-server/users.d/*.xml - files with user settings adjustments
  • /docker-entrypoint-initdb.d/ - folder with database initialization scripts (see below).

Linux capabilities

ClickHouse has some advanced functionality, which requires enabling several Linux capabilities They’re optional and can be enabled using the following docker command-line arguments:
For more information see “Configuring CAP_IPC_LOCK and CAP_SYS_NICE Capabilities in Docker”

Configuration

The container exposes port 8123 for the HTTP interface and port 9000 for the native client. ClickHouse configuration is represented with a file “config.xml” (documentation)

Start server instance with custom configuration

Start server as custom user

When you use the image with local directories mounted, you probably want to specify the user to maintain the proper file ownership. Use the --user argument and mount /var/lib/clickhouse and /var/log/clickhouse-server inside the container. Otherwise, the image will complain and not start.

Start server from root

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

How to create default database and user on start

Set CLICKHOUSE_DB to create a database when the container first initializes the data directory. Set CLICKHOUSE_USER and CLICKHOUSE_PASSWORD to configure a user. If you omit CLICKHOUSE_USER, the image uses the default user. CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 lets the configured user create users and grant privileges. In the example below, this is username. When you set a non-default username or a password, SQL access management is disabled if you omit this variable or set it to 0.

Managing default user

With the stock configuration, if you use the default user without a password and leave CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT unset or set it to 0, the user retains SQL access management and can connect only from localhost. CLICKHOUSE_SKIP_USER_SETUP=1 skips user configuration even if you set a username, password, or access-management flag. With the stock configuration, this allows network connections as the default user without a password.

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.
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:

Image without a shell

The default image (the tags without a suffix) is built FROM scratch. It contains the statically linked clickhouse binary, its configuration, and the few system files it needs: CA certificates, /etc/passwd. There is no shell, no package manager, no C library, and no other programs, so the only software to keep patched is ClickHouse. The logic of the entrypoint (preparing the directories, creating the user from CLICKHOUSE_USER and CLICKHOUSE_PASSWORD, creating CLICKHOUSE_DB, running the scripts from /docker-entrypoint-initdb.d) is built into the binary as clickhouse docker-init, and is configured with the same environment variables. The differences from the -ubuntu image:
  • The *.sql and *.sql.gz init scripts work as usual. A *.sh script needs a shell: an executable script is run directly, and a non-executable one is run by sh -e (instead of being sourced), so it stops at the first failed command, like with set -e in entrypoint.sh. If there is no shell, the container stops with an error, rather than starting without the initialization.
  • docker run clickhouse/clickhouse-server <command> and docker exec can run only the ClickHouse tools, such as clickhouse-client or clickhouse-local.
When you need a shell, for example for troubleshooting, mount one into the container. It has to be statically linked, such as busybox from the busybox-static package of Debian and Ubuntu:
Alternatively, use the image with the -ubuntu suffix.

User-defined functions and executable scripts

Executable user-defined functions, the executable table function, the Executable table engine and executable dictionaries start programs from user_scripts_path (/var/lib/clickhouse/user_scripts/). The image without a shell can run only statically linked programs, because it has no shell, no interpreter such as Python, and no C library. Mount the programs and the configuration of the functions (a file matching *_function.*ml) into the container:
For scripts, build an image on top of the image with the -ubuntu suffix and install the interpreter:
The configuration of the server sets filesystem_isolation to best_effort. Docker does not let the server create the namespaces it needs unless the container has CAP_SYS_ADMIN, so by default the server runs without the isolation and logs a warning. If the container has CAP_SYS_ADMIN and its security profile allows mounting filesystems, the server isolates itself, and the interpreters, libraries and data of the scripts have to be listed in filesystem_isolation_paths. Driver-based user-defined functions need dynamic_user_defined_executable_functions_path declared as <read_write_executable> when the isolation is in force, and need the tools that the drivers run. See Executable UDFs with filesystem isolation.