skip to Main Content

I have a docker-compose.yml file with the tidb container setup like this

  ti-db:
    image: pingcap/tidb
    container_name: ti-db
    ports:
      - 4000:4000
    logging:
      driver: none
    volumes:
      - ./storage/tidb:/var/lib/mysql
    

I am trying to have it create a database called "messageservice" on startup but cannot get it to work.

In the same docker-compose file I have a mysql container where I create initial databases using init.sql file and mapping it to docker-entrypoint-initdb.d like this

 - ./dbInit/init.sql:/docker-entrypoint-initdb.d/init.sql

But when I do the same thing for TiDb it does not work.

Is there a way I can setup the docker-compose file so the database gets created on docker compose up command ?

2

Answers


  1. And what do you have on file init.sql?

    services:
      ti-db:
        image: pingcap/tidb
        container_name: ti-db
        ports:
          - 4000:4000
        logging:
          driver: none
        volumes:
          - ./storage/tidb:/var/lib/mysql
          - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    

    Or you can try without the file by using "command"

    services:
      ti-db:
        image: pingcap/tidb
        container_name: ti-db
        ports:
          - 4000:4000
        logging:
          driver: none
        volumes:
          - ./storage/tidb:/var/lib/mysql
        command: --store=tikv --path="127.0.0.1:2379" --log-file="/var/log/tidb.log" --log-level=debug && mysql -h127.0.0.1 -P4000 -uroot -e "create database messageservice;"
    
    Login or Signup to reply.
  2. tidb-docker-compose doesn’t support ./dbInit/..., You need to execute the initialization SQL file manually.

    BTW, I recommend you to ask questions here: https://ask.pingcap.com/, this is the official forum.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search