Search code examples
dockerdocker-composeclickhouseyandex

creating db and tables in a dockerized Clickhouse instance from docker-compose file


My requirement is to create DB and Tables in Clickhouse when I'm bringing it up using docker-compose. If it is mysql, I do it as below :

mysql_1:
      image: mysql:5.7.16
      environment:
        MYSQL_DATABASE: "one"
        MYSQL_USER: "one_user"
        MYSQL_PASSWORD: "one_user_pass"
        MYSQL_ROOT_PASSWORD: "root"
        MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
      volumes:
       - ./data/one:/docker-entrypoint-initdb.d
      ports:
        - "3306:3306"

Is there any way to achieve the same for a Clickhouse instance?


Solution

  • I found a not so clean solution for this. It is basically mounting a host directory into the container and running all the "create tables" and "insert" statements, would be persisted as long as we do not clean up the mounted folder!!

    clickhouse:
      image: yandex/clickhouse-server:18.10
      ports:
        - "8123:8123"
        - "9000:9000"
      volumes:
       - ./data/clickhouse/data:/var/lib/clickhouse