Issues with Default Deployment of TiDB Using docker-compose.yml

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 使用docker-compose.yml默认部署TiDB相关映射问题

| username: wenrou

[TiDB Usage Environment] Production Environment
[TiDB Version]
[Reproduction Path]
[Encountered Problem: Problem Phenomenon and Impact]
TiDB deployed using docker-compose.yml, default initial file execution. How to map the corresponding source file of the TiDB database? Not sure if this file needs to be modified, if so, how to modify it, if not, which file needs to be modified.
[Resource Configuration]
[Attachment: Screenshot/Log/Monitoring]

| username: Billmay表妹 | Original post link

If you are using Docker Compose to deploy TiDB, the source files of the TiDB database should be inside the container, not on the host machine. If you want to map the source files of the TiDB database to the host machine, you can achieve this by modifying the Docker Compose file.

Specifically, you need to add a volume to the TiDB container in the Docker Compose file to map the internal data directory of the container to a directory on the host machine. For example, suppose your Docker Compose file contains the following content:

version: '3'

services:
  tidb:
    image: pingcap/tidb:latest
    ports:
      - "4000:4000"
      - "10080:10080"
    environment:
      - "TZ=Asia/Shanghai"
    volumes:
      - tidb-data:/var/lib/mysql

volumes:
  tidb-data:

In the above Docker Compose file, we added a volume named tidb-data to the TiDB container and mapped the internal /var/lib/mysql directory of the container to this volume. This way, the data inside the TiDB container will be saved to the tidb-data volume on the host machine.

If you want to map the source files of the TiDB database to a directory on the host machine, you can modify the volumes section above to:

volumes:
  tidb-data:
  tidb-source:
    driver: local

Then, in the TiDB container, mount the directory where the source files of the TiDB database are located to the tidb-source volume. For example, suppose the source files of the TiDB database are in the /usr/local/tidb/source directory inside the container, you can modify the Docker Compose file to:

version: '3'

services:
  tidb:
    image: pingcap/tidb:latest
    ports:
      - "4000:4000"
      - "10080:10080"
    environment:
      - "TZ=Asia/Shanghai"
    volumes:
      - tidb-data:/var/lib/mysql
      - tidb-source:/usr/local/tidb/source

volumes:
  tidb-data:
  tidb-source:
    driver: local

This way, the /usr/local/tidb/source directory inside the TiDB container will be mapped to the tidb-source volume on the host machine. You can find the source files of the TiDB database in the tidb-source volume on the host machine.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.