TDengine/packaging/docker
freemine 6267763e85
Freemine.cmake.3.0 (#30663)
* chore(ci): with cmake verbose, temporarily

* chore(cmake): prefer Threads::Threads

* fix(cmake): debug building gtest on ubuntu 20.04 for the moment

* fix(cmake): try adding Threads::Threads

* fix(cmake): debug building gtest on ubuntu 20.04 for the moment

* fix(cmake): revert taosd-ci-build.yml

* fix(cmake): debug building on ubuntu 20.04 for the moment

* fix(cmake): debug building on ubuntu 20.04 for the moment

* fix(cmake): debug building on ubuntu 20.04 for the moment, adding dl right after DEP_ext_libuv

* fix(cmake): debug building on ubuntu 20.04 for the moment, try full run

* fix(cmake): fix building on ubuntu 20.04

* fix(cmake): dl is only valid in non-windows platform

* fix(cmake): dl order

* refactor(cmake): adjust option/cache variables for external dependencies

* refactor(cmake): mv patch files from contrib/ to cmake/

* refactor(cmake): typo

* refactor(cmake): adding cache on ci

* refactor(cmake):
1. ext_lzma2 is only used by Linux
2. fix bug in taosd-ci-build.yml

* enh: adding functionalities of build.sh

* fix(ci): `cmake -B` shall maintain consistency

* refactor(cmake): LOCAL_REPO/LOCAL_URL as cache variable

* refactor(cmake): taosadapter to be built in main build directory rather than .externals

* refactor(cmake): adding rpath for taosadapter, linux now

* refactor(cmake): adding rpath for taosadapter, macos now

* chore(cmake): remove some comments

* debug(ci): bypass TD_EXTERNALS_USE_ONLY

* debug(ci): bypass .externals caching for the moment

* fix(cmake): temporarily use taosadapter/main branch because this branch(freemine.cmake.3.0) has not include taos_fetch_fields_e from upstream

* refactor(cmake): clean GIT_TAG/GIT_SHALLOW pairs

* enh(ci): use build.sh rather than hard-coded in taosd-ci-build.yml, linux for now

* debug(ci): undefined __isoc23_strtoull

* debug(ci): benchmarkTest

* debug(ci): what if use_only = off

* debug(ci): remove .externals to make a refresh build

* debug(ci): back to cache, and ls files of gtest

* debug(ci): remove find coz {} not escaped

* debug(ci): cache key seems missing "matrix.os"

* refactor(ci): fixed cache key and reopen macos/windows

* chore(ci): literally -j4

* chore(ci): Trigger GitHub Actions re-run

* chore(ci): Trigger GitHub Actions re-run

* fix(ci): typo

* chore(ci): JOBS calculated by build.sh itself

* refactor(ci): enable WEBSOCKET in build.sh by default

* refactor(ci): enable WEBSOCKET in build.sh by default, macOS

* chore(cmake): remove obsoletes

* refactor(ci): stop service before running taosd

* chore(ci): `./build.sh install` just install TDengine, you will have to start taosd by `./build.sh start`

* refactor(cmake): adding source code found on http://emfisis.physics.uiowa.edu/Software/C/libargp/

* refactor(cmake): moving jansson/snappy/avro to .externals, and porting BUILD_TEST/WEBSOCKET on Windows

* refactor(cmake): porting linux

* refactor(cmake): porting macos
1. check argp.h
2. re-enable building taosdump

* refactor(cmake): porting linux
1. adjust CMAKE_C/CXX_FLAGS

* refactor(cmake): porting windows, adjust CMAKE_C/CXX_FLAGS

* refactor(cmake): use cmake_parse_arguments in macro INIT_EXT

* refactor(cmake): format ci cache directives

* refactor(cmake): adding comments for ci externals-cache directives

* refactor(cmake): adding check_env.cmake to checking libraries installed on the system

* refactor(cmake): porting linux, make homebrew-installed-libs available

* refactor(cmake): remove BYPRODUCTS from INIT_EXT macro

* refactor(cmake): INC_DIR is oneValueArg

* refactor(cmake): taosdump depends on ext_xz(LZMA)

* refactor(cmake): add copy_pthreadVC3 target on windows

* refactor(cmake): mv taosd-ci-build.yml to tdengine-build.yml

* chore(ci): try to fix yml syntax error

* refactor(cmake): use brew --prefix to get HomeBrew's install path

* refactor(cmake): typo

* debug(ci): build and cache externals first

* debug(ci): adding -Wno-stringop-overread for the moment

* debug(ci): make Threads::Threads public from os target

* debug(ci): make os public

* debug(ci): re-enable start and test

* debug(ci): let it go even if taosBenchmark failed

* debug(ci): copy logic from TDengine/main

* debug(ci): try ./build.sh start/test

* debug(ci): revert to original simple test logic in ci, taosBenchark/taos

* chore(cmake): code-convention and ci-logic

* debug(ci): show versions

* debug(ci): forcefully use specific GIT_TAG by commit-id for taos-connector-rust.git and taosadapter.git

* refactor(cmake): remove empty lines

* debug(ci): typo

* debug(ci): set supportVnodes to 256 before starting taosd

* debug(ci): fix: sudo and pipe

* debug(ci): cat /etc/taos/taos.cfg to check if supportVnodes effective

* debug(ci): cat forceReadConfig to taos.cfg

* debug(ci): adding taos -s "show dnodes"

* debug(ci): print more info

* debug(ci):
1. git log .... in an independant step
2. sleep 3 deliberately

* build: release ver-3.3.6.0

* chore(ci): comment and remove unnecessary code

* refactor(ci): cleanup tools/CMakeLists.txt
1. remove unnecessary or uneffective codes
2. better approach to pass compile flags to go

* chore(cmake): remove unnecessary code

* merge(cmake): porting linux

* merge(cmake): porting macOS

* merge(cmake): porting windows

* merge(cmake): pitfall fix: use literal format string instead

* merge(cmake): ver-3.3.6.0 for both taosadatper and taosws

* merge(cmake): adjust ci for debug purposes

* merge(cmake): add dependenices to make sure native built

* merge(main): link os

* merge(main): revert to main

* chore(cmake): remove freemine'd comments

* chore(cmake): make github ci to run with empty change

* refactor(cmake): remove unnecessaries

* refactor(cmake): remove unnecessaries

* chore(cmake):
1. remove taosudf in build.sh::do_purge
2. packaging taosBenchmark

* chore(cmake):
1. typo corrections
2. add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to bypass compatibility check imposed by latest cmake since 4.0

* chore(cmake): show cmake version

* chore(cmake): add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to bypass compatibility check imposed by latest cmake since 4.0

* chore(cmake): typo

* chore(cmake): remove unnecessaries

* cmake: debug enterprise compilation

* refactor: preparatory work before merging the freemin PR

* refactor(cmake): revert to d91205594a

* refactor(cmake): optimize by adjusting cache key

* chore(cmake): make github ci to run with empty change

* refactor(cmake): move libs3 and azure to external.cmake

* refactor(cmake): porting macOS

* refactor(cmake): move cos to external.cmake

* refactor(cmake): bypass s3/azure/cos on windows for the moment

* refactor(cmake): try find_package(Threads)

* refactor(cmake): add dl/pthread in libs3

* refactor(cmake): enable s3/azure for the moment, hard-coded

* refactor(cmake): adjust BUILD_WITH_ANALYSIS option

* refactor(cmake):
1. enum AVROTYPE => enum enAVROTYPE
2. remove INSTALL(CODE ...) from tools/taos-tools/CMakeLists.txt

* refactor(cmake): portint macOS and typo

* refactor(cmake): ticking external cache key to force refresh external building

* refactor(cmake): remove obsoletes

* refactor(cmake): remove obsoletes

* refactor(cmake): remove obsoletes, contrib/deps-download related

* refactor(cmake): adding build.bat, and use build.bat in .github/workflows/tdengine-build.yml

* refactor(cmake):
1. call .\build.bat
2. remove POST_BUILD which is not valid in this signature of add_custom_command

* refactor(ci): use 'NMake Makefiles JOM'

* refactor(ci): typo

* refactor(ci): debug

* refactor(ci): debug

* refactor(ci): debug

* refactor(ci): use call on windows

* refactor(cmake): move utils/TSZ to contrib/TSZ

* chore(cmake): make github ci to run with empty change

* refactor(cmake): mv cmake.* -> *.cmake and related in CMakeLists.txt

* refactor(cmake): debugging integrating community

* refactor(cmake): debugging integrating community

* chore(cmake): make github ci to run with empty change

* refactor(cmake): revert geos.git back to 3.12.0

* refactor(cmake): revert doc/** to main branch

* refactor(cmake): revert tests/** to main branch, except tests/taosc_test/CMakeLists.txt

* refactor(cmake): revert test/cases/** to main branch

* refactor(cmake): revert test/docs/** to main branch

* refactor(cmake): revert tools/taos-tools/deps/{avro,jansson,libargp,snappy,zlib-1.2.13} to main branch, which need to be removed later

* refactor(ci): revert .github/workflows/{deploy-case-docs.yml,tdengine-doc-build.yml} to main branch

* refactor(cmake): revert tcommon.h and related to main branch

* refactor(cmake): revert test/* stuffs back to main branch

* refactor(cmake): revert libuv.git back to v1.49.2

* refactor(cmake): revert .h/.c and related to main branch

* refactor(cmake): typo format string

* refactor(cmake): typo correction, incorrect use of macro `assert`

* refactor(cmake): adding /wd4028 to bypass thttp.c under enterprise build for the moment

* refactor(cmake):
1. adding some rules to .gitignore for the last resort to save
2. adding source files manually to source/libs/parser/CMakeLists.txt to exclude potential sql.c generated by old build system

* refactor(cmake): add -Wno-unused-result for the moment

* refactor(cmake): adjust target dependencies

* refactor(cmake): tweaking building of mxml

* refactor(cmake): adjust externals CMAKE_ARGS to save compilation time

* refactor(cmake): temporarily use tomchon-patch-3

* refactor(cmake): temporarily adding dumpbin directives

* refactor(cmake): adding NODEFAULTLIB temporarily for debugging purpose

* refactor(cmake): adding NODEFAULTLIB:libcpmt temporarily for debugging purpose

* refactor(cmake): adding NODEFAULTLIB:cpmt temporarily for debugging purpose

* chore(cmake): make github ci to run with empty change

* chore(cmake): make github ci to run with empty change

* refactor(ci): use freemine.debug branch for the moment

* refactor(ci): revert back to use run-tests-on-windows.yml of tomchon-patch-3 branch

* chore(cmake): make github ci to run with empty change

* refactor(cmake): remove temporary debug directives

* refactor(cmake): move cmake_policy(..CMP0135..) to the root of this project

* refactor(cmake): Remove temporary debugging conditional and restore original logic

* chore(cmake): adding -B in army tests

* chore(cmake): make github ci to run with empty change

* chore(cmake): revert: adding -B in army tests

* refactor(cmake):
1. use ver-3.3.6.3 of taosadapter
2. pitfall fix: do not link with taosws for taos shell

* refactor(cmake): revert taosadapter to ver-3.3.6.0

* chore(cmake): adding logging message in more detail

* chore(cmake): adding logging message in more detail

* chore(ci): debugging by using ls -l

* chore(ci): typo

* chore(ci): typo

* refactor(cmake): revert to remove debug code, and taosadapter to ver-3.3.6.3

* refactor(cmake): remove DEP_ext_taosws

* chore(cmake): make github ci to run with empty change

* chore(cmake): make github ci to run with empty change

* chore(cmake): make github ci to run with empty change

* chore(cmake): make github ci to run with empty change

* chore(cmake): typo correction: utils/test/c/sml_test.c

* debug(cmake): test cases debug

* chore(cmake): make github ci to run with empty change

* chore(ci): using tomchon-patch-3 branch for run-tests-on-linux for the moment

* chore(cmake): make github ci to run with empty change

* debug(test): revert utils/test/c/sml_test.c back to tdengine/main branch

* debug(test): adding VERBOSE=1 and gcc --version

* debug(test): revert tests/parallel_test/cases.task back to tdengine/main branch

* debug: add log in run_case.sh

* fix: test log

* fix: docker run privileged

* tes: add debug test in  cases.task

* refactor(cmake): remove ref to \contrib\<dep-name> and ~/.cos-local-{1,2} from CMakeLists.txt(s)

* refactor(cmake): make taosudf link with libtaos.so

* chore(cmake): fix compiler warning as error problem

* refactor(cmake): revert 7d7f03832d

* chore(cmake): only udf.sim and udfpy.sim for the moment

* debug(ci): debug udf.sim for the moment

* debug(ci): debug udf.sim for the moment

* debug(ci): debug udf.sim for the moment

* debug(ci): debug only udf.sim for the moment

* debug(ci): debug only udf.sim for the moment, using tee

* debug(ci): debug only udf.sim for the moment, revert using tee

* debug(ci): debug only udf.sim for the moment, adding TAOS_LIB again

* debug(cmake): adding -rdynamic for the moment

* debug(cmake): re-adding udfpy.sim

* debug(cmake): do NOT run with Sanitizer for udfpy.sim for the moment

* chore(cmake): revert cases.task, and remove ubuntu-20.04 from tdengine-build.yml

* refactor(cmake): using ENABLE_EXPORTS to export symbols in taosudf

* chore(cmake): make github ci to run with empty change

* chore(cmake): remove stuffs for debug purpose and revert

---------

Co-authored-by: support-platform <it@taosdata.com>
Co-authored-by: Simon Guan <slguan@taosdata.com>
Co-authored-by: Simon Guan <guanshengliang@qq.com>
Co-authored-by: haoranchen <haoran920c@163.com>
2025-04-19 14:03:29 +08:00
..
bin Freemine.cmake.3.0 (#30663) 2025-04-19 14:03:29 +08:00
dockerbuild.sh enh: update DockerfileTDgpt and run-shell 2025-03-25 15:38:59 +08:00
dockerbuildi.sh test(driver):C# CI failed for longarch64 pr-17982 (#18030) 2022-11-10 21:06:20 +08:00
Dockerfile enh: rm built-in parameters 2025-03-27 18:59:50 +08:00
DockerfileTDgpt enh: update DockerfileTDgpt and run-shell 2025-03-25 15:38:59 +08:00
DockerfileTDgpt.base enh: adjust seq and add timer-moe model 2025-03-24 19:05:19 +08:00
dockerManifest.sh fix: docker doc refine (#20101) 2023-02-22 21:15:33 +08:00
entrypoint.sh enh: update DockerfileTDgpt and run-shell 2025-03-25 15:38:59 +08:00
README.md fix: docker doc refine (#20101) 2023-02-22 21:15:33 +08:00

TDengine Docker Image Quick Reference

What is TDengine?

TDengine is an open-sourced big data platform under GNU AGPL v3.0, designed and optimized for the Internet of Things (IoT), Connected Cars, Industrial IoT, and IT Infrastructure and Application Monitoring. Besides the 10x faster time-series database, it provides caching, stream computing, message queuing and other functionalities to reduce the complexity and cost of development and operation.

  • 10x Faster on Insert/Query Speeds: Through the innovative design on storage, on a single-core machine, over 20K requests can be processed, millions of data points can be ingested, and over 10 million data points can be retrieved in a second. It is 10 times faster than other databases.

  • 1/5 Hardware/Cloud Service Costs: Compared with typical big data solutions, less than 1/5 of computing resources are required. Via column-based storage and tuned compression algorithms for different data types, less than 1/10 of storage space is needed.

  • Full Stack for Time-Series Data: By integrating a database with message queuing, caching, and stream computing features together, it is no longer necessary to integrate Kafka/Redis/HBase/Spark or other software. It makes the system architecture much simpler and more robust.

  • Powerful Data Analysis: Whether it is 10 years or one minute ago, data can be queried just by specifying the time range. Data can be aggregated over time, multiple time streams or both. Ad Hoc queries or analyses can be executed via TDengine shell, Python, R or Matlab.

  • Seamless Integration with Other Tools: Telegraf, Grafana, Matlab, R, and other tools can be integrated with TDengine without a line of code. MQTT, OPC, Hadoop, Spark, and many others will be integrated soon.

  • Zero Management, No Learning Curve: It takes only seconds to download, install, and run it successfully; there are no other dependencies. Automatic partitioning on tables or DBs. Standard SQL is used, with C/C++, Python, JDBC, Go and RESTful connectors.

How to use this image

Starting TDengine

The TDengine image starts with the HTTP service activated by default, using the following command:

docker run -d --name tdengine -p 6041:6041 tdengine/tdengine

The above command starts a container named "tdengine" and maps the HTTP service port 6041 to the host port 6041. You can verify that the HTTP service provided in this container is available using the following command.

curl -u root:taosdata -d "show databases" localhost:6041/rest/sql

The TDengine client taos can be executed in this container to access TDengine using the following command.

$ docker exec -it tdengine taos

taos> show databases;
              name              |
=================================
 information_schema             |
 performance_schema             |
Query OK, 2 row(s) in set (0.002843s)

The TDengine server running in the container uses the container's hostname to establish a connection. Using TDengine CLI or various connectors (such as JDBC-JNI) to access the TDengine inside the container from outside the container is more complicated. So the above is the simplest way to access the TDengine service in the container and is suitable for some simple scenarios. Please refer to the next section if you want to access the TDengine service in the container from outside the container using TDengine CLI or various connectors for complex scenarios.

Start TDengine on the host network

docker run -d --name tdengine --network host tdengine/tdengine

The above command starts TDengine on the host network and uses the host's FQDN to establish a connection instead of the container's hostname. It is the equivalent of using systemctl to start TDengine on the host. If the TDengine client is already installed on the host, you can access it directly with the following command.

$ taos

taos> show dnodes;
   id   |           end_point            | vnodes | cores  |   status   | role  |       create_time       |      offline reason      |
======================================================================================================================================
      1 | myhost:6030           |      1 |      8 | ready      | any   | 2022-01-17 22:10:32.619 |                          |
Query OK, 1 row(s) in set (0.003233s)

Start TDengine with the specified hostname and port

The TAOS_FQDN environment variable or the fqdn configuration item in taos.cfg allows TDengine to establish a connection at the specified hostname. This approach provides greater flexibility for deployment.

docker run -d \
   --name tdengine \
   -e TAOS_FQDN=tdengine \
   -p 6030-6049:6030-6049 \
   -p 6030-6049:6030-6049/udp \
   tdengine/tdengine

The above command starts a TDengine service in the container, which listens to the hostname tdengine, and maps the container's port segment 6030 to 6049 to the host's port segment 6030 to 6049 (both TCP and UDP ports need to be mapped). If the port segment is already occupied on the host, you can modify the above command to specify a free port segment on the host. If rpcForceTcp is set to 1, you can map only the TCP protocol.

Next, ensure the hostname "tdengine" is resolvable in /etc/hosts.

echo 127.0.0.1 tdengine |sudo tee -a /etc/hosts

Finally, the TDengine service can be accessed from the TDengine CLI or any connector with "tdengine" as the server address.

taos -h tdengine -P 6030

If set TAOS_FQDN to the same hostname, the effect is the same as "Start TDengine on host network".

Start TDengine on the specified network

You can also start TDengine on a specific network. Perform the following steps:

  1. First, create a docker network named td-net

    docker network create td-net
    
  2. Start TDengine

    Start the TDengine service on the td-net network with the following command:

    docker run -d --name tdengine --network td-net \
       -e TAOS_FQDN=tdengine \
       tdengine/tdengine
    
  3. Start the TDengine client in another container on the same network

    docker run --rm -it --network td-net -e TAOS_FIRST_EP=tdengine tdengine/tdengine taos
    # or
    #docker run --rm -it --network td-net -e tdengine/tdengine taos -h tdengine
    

Launching a client application in a container

If you want to start your application in a container, you need to add the corresponding dependencies on TDengine to the image as well, e.g.

FROM ubuntu:20.04
RUN apt-get update && apt-get install -y wget
ENV TDENGINE_VERSION=3.0.0.0
RUN wget -c https://www.taosdata.com/assets-download/3.0/TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz \
   && tar xvf TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz \
   && cd TDengine-client-${TDENGINE_VERSION} \
   && ./install_client.sh \
   && cd ../ \
   && rm -rf TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz TDengine-client-${TDENGINE_VERSION}
## add your application next, eg. go, build it in builder stage, copy the binary to the runtime
#COPY --from=builder /path/to/build/app /usr/bin/
#CMD ["app"]

Here is an example GO program:

/*
 * In this test program, we'll create a database and insert 4 records then select out.
 */
package main

import (
    "database/sql"
    "flag"
    "fmt"
    "time"

    _ "github.com/taosdata/driver-go/v3/taosSql"
)

type config struct {
    hostName   string
    serverPort string
    user       string
    password   string
}

var configPara config
var taosDriverName = "taosSql"
var url string

func init() {
    flag.StringVar(&configPara.hostName, "h", "", "The host to connect to TDengine server.")
    flag.StringVar(&configPara.serverPort, "p", "", "The TCP/IP port number to use for the connection to TDengine server.")
    flag.StringVar(&configPara.user, "u", "root", "The TDengine user name to use when connecting to the server.")
    flag.StringVar(&configPara.password, "P", "taosdata", "The password to use when connecting to the server.")
    flag.Parse()
}

func printAllArgs() {
    fmt.Printf("============= args parse result: =============\n")
    fmt.Printf("hostName:             %v\n", configPara.hostName)
    fmt.Printf("serverPort:           %v\n", configPara.serverPort)
    fmt.Printf("usr:                  %v\n", configPara.user)
    fmt.Printf("password:             %v\n", configPara.password)
    fmt.Printf("================================================\n")
}

func main() {
    printAllArgs()

    url = "root:taosdata@/tcp(" + configPara.hostName + ":" + configPara.serverPort + ")/"

    taos, err := sql.Open(taosDriverName, url)
    checkErr(err, "open database error")
    defer taos.Close()

    taos.Exec("create database if not exists test")
    taos.Exec("use test")
    taos.Exec("create table if not exists tb1 (ts timestamp, a int)")
    _, err = taos.Exec("insert into tb1 values(now, 0)(now+1s,1)(now+2s,2)(now+3s,3)")
    checkErr(err, "failed to insert")
    rows, err := taos.Query("select * from tb1")
    checkErr(err, "failed to select")

    defer rows.Close()
    for rows.Next() {
        var r struct {
            ts time.Time
            a  int
        }
        err := rows.Scan(&r.ts, &r.a)
        if err != nil {
            fmt.Println("scan error:\n", err)
            return
        }
        fmt.Println(r.ts, r.a)
    }
}

func checkErr(err error, prompt string) {
    if err != nil {
        fmt.Println("ERROR: %s\n", prompt)
        panic(err)
    }
}

Here is the full Dockerfile:

FROM golang:1.17.6-buster as builder
ENV TDENGINE_VERSION=3.0.0.0
RUN wget -c https://www.taosdata.com/assets-download/3.0/TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz \
   && tar xvf TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz \
   && cd TDengine-client-${TDENGINE_VERSION} \
   && ./install_client.sh \
   && cd ../ \
   && rm -rf TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz TDengine-client-${TDENGINE_VERSION}
WORKDIR /usr/src/app/
ENV GOPROXY="https://goproxy.io,direct"
COPY ./main.go ./go.mod ./go.sum /usr/src/app/
RUN go env
RUN go mod tidy
RUN go build

FROM ubuntu:20.04
RUN apt-get update && apt-get install -y wget
ENV TDENGINE_VERSION=3.0.0.0
RUN wget -c https://www.taosdata.com/assets-download/3.0/TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz \
   && tar xvf TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz \
   && cd TDengine-client-${TDENGINE_VERSION} \
   && ./install_client.sh \
   && cd ../ \
   && rm -rf TDengine-client-${TDENGINE_VERSION}-Linux-x64.tar.gz TDengine-client-${TDENGINE_VERSION}

## add your application next, eg. go, build it in builder stage, copy the binary to the runtime
COPY --from=builder /usr/src/app/app /usr/bin/
CMD ["app"]

Now that we have main.go, go.mod, go.sum, app.dockerfile, we can build the application and start it on the td-net network.

$ docker build -t app -f app.dockerfile
$ docker run --rm --network td-net app -h tdengine -p 6030
============= args parse result: =============
hostName:             tdengine
serverPort:           6030
usr:                  root
password:             taosdata
================================================
2022-01-17 15:56:55.48 +0000 UTC 0
2022-01-17 15:56:56.48 +0000 UTC 1
2022-01-17 15:56:57.48 +0000 UTC 2
2022-01-17 15:56:58.48 +0000 UTC 3
2022-01-17 15:58:01.842 +0000 UTC 0
2022-01-17 15:58:02.842 +0000 UTC 1
2022-01-17 15:58:03.842 +0000 UTC 2
2022-01-17 15:58:04.842 +0000 UTC 3
2022-01-18 01:43:48.029 +0000 UTC 0
2022-01-18 01:43:49.029 +0000 UTC 1
2022-01-18 01:43:50.029 +0000 UTC 2
2022-01-18 01:43:51.029 +0000 UTC 3

Start the TDengine cluster with docker-compose

  1. The following docker-compose file starts a TDengine cluster with three nodes.
version: "3"
services:
  td-1:
    image: tdengine/tdengine:$VERSION
    environment:
      TAOS_FQDN: "td-1"
      TAOS_FIRST_EP: "td-1"
    volumes:
      - taosdata-td1:/var/lib/taos/
      - taoslog-td1:/var/log/taos/
  td-2:
    image: tdengine/tdengine:$VERSION
    environment:
      TAOS_FQDN: "td-2"
      TAOS_FIRST_EP: "td-1"
    volumes:
      - taosdata-td2:/var/lib/taos/
      - taoslog-td2:/var/log/taos/
  td-3:
    image: tdengine/tdengine:$VERSION
    environment:
      TAOS_FQDN: "td-3"
      TAOS_FIRST_EP: "td-1"
    volumes:
      - taosdata-td3:/var/lib/taos/
      - taoslog-td3:/var/log/taos/
volumes:
  taosdata-td1:
  taoslog-td1:
  taosdata-td2:
  taoslog-td2:
  taosdata-td3:
  taoslog-td3:

:::note

  • The VERSION environment variable is used to set the tdengine image tag
  • TAOS_FIRST_EP must be set on the newly created instance so that it can join the TDengine cluster; if there is a high availability requirement, TAOS_SECOND_EP needs to be used at the same time :::
  1. Start the cluster

    $ VERSION=3.0.0.0 docker-compose up -d
    Creating network "test_default" with the default driver
    Creating volume "test_taosdata-td1" with default driver
    Creating volume "test_taoslog-td1" with default driver
    Creating volume "test_taosdata-td2" with default driver
    Creating volume "test_taoslog-td2" with default driver
    Creating test_td-1_1       ... done
    Creating test_arbitrator_1 ... done
    Creating test_td-2_1       ... done
    
  2. Check the status of each node

    $ docker-compose ps
          Name                     Command               State                                                                Ports
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    test_arbitrator_1   /usr/bin/entrypoint.sh tar ...   Up      6030/tcp, 6031/tcp, 6032/tcp, 6033/tcp, 6034/tcp, 6035/tcp, 6036/tcp, 6037/tcp, 6038/tcp, 6039/tcp, 6040/tcp, 6041/tcp, 6042/tcp
    test_td-1_1         /usr/bin/entrypoint.sh taosd     Up      6030/tcp, 6031/tcp, 6032/tcp, 6033/tcp, 6034/tcp, 6035/tcp, 6036/tcp, 6037/tcp, 6038/tcp, 6039/tcp, 6040/tcp, 6041/tcp, 6042/tcp
    test_td-2_1         /usr/bin/entrypoint.sh taosd     Up      6030/tcp, 6031/tcp, 6032/tcp, 6033/tcp, 6034/tcp, 6035/tcp, 6036/tcp, 6037/tcp, 6038/tcp, 6039/tcp, 6040/tcp, 6041/tcp, 6042/tcp
    
  3. Show dnodes via TDengine CLI

$ docker-compose exec td-1 taos -s "show dnodes"

taos> show dnodes
     id      |            endpoint            | vnodes | support_vnodes |   status   |       create_time       |              note              |
======================================================================================================================================
           1 | td-1:6030                      |      0 |             32 | ready      | 2022-08-19 07:57:29.971 |                                |
           2 | td-2:6030                      |      0 |             32 | ready      | 2022-08-19 07:57:31.415 |                                |
           3 | td-3:6030                      |      0 |             32 | ready      | 2022-08-19 07:57:31.417 |                                |
Query OK, 3 rows in database (0.021262s)

taosAdapter

  1. taosAdapter is enabled by default in the TDengine container. If you want to disable it, specify the environment variable TAOS_DISABLE_ADAPTER=true at startup

  2. At the same time, for flexible deployment, taosAdapter can be started in a separate container

    services:
      # ...
      adapter:
        image: tdengine/tdengine:$VERSION
        command: taosadapter
    

    Suppose you want to deploy multiple taosAdapters to improve throughput and provide high availability. In that case, the recommended configuration method uses a reverse proxy such as Nginx to offer a unified access entry. For specific configuration methods, please refer to the official documentation of Nginx. Here is an example:

version: "3"

networks:
  inter:

services:
  td-1:
    image: tdengine/tdengine:$VERSION
    networks:
      - inter
    environment:
      TAOS_FQDN: "td-1"
      TAOS_FIRST_EP: "td-1"
    volumes:
      - taosdata-td1:/var/lib/taos/
      - taoslog-td1:/var/log/taos/
  td-2:
    image: tdengine/tdengine:$VERSION
    networks:
      - inter
    environment:
      TAOS_FQDN: "td-2"
      TAOS_FIRST_EP: "td-1"
    volumes:
      - taosdata-td2:/var/lib/taos/
      - taoslog-td2:/var/log/taos/
  adapter:
    image: tdengine/tdengine:$VERSION
    entrypoint: "taosadapter"
    networks:
      - inter
    environment:
      TAOS_FIRST_EP: "td-1"
      TAOS_SECOND_EP: "td-2"
    deploy:
      replicas: 4
  nginx:
    image: nginx
    depends_on:
      - adapter
    networks:
      - inter
    ports:
      - 6041:6041
      - 6044:6044/udp
    command: [
        "sh",
        "-c",
        "while true;
        do curl -s http://adapter:6041/-/ping >/dev/null && break;
        done;
        printf 'server{listen 6041;location /{proxy_pass http://adapter:6041;}}'
        > /etc/nginx/conf.d/rest.conf;
        printf 'stream{server{listen 6044 udp;proxy_pass adapter:6044;}}'
        >> /etc/nginx/nginx.conf;cat /etc/nginx/nginx.conf;
        nginx -g 'daemon off;'",
      ]
volumes:
  taosdata-td1:
  taoslog-td1:
  taosdata-td2:
  taoslog-td2:

Deploy with docker swarm

If you want to deploy a container-based TDengine cluster on multiple hosts, you can use docker swarm. First, to establish a docker swarm cluster on these hosts, please refer to the official docker documentation.

The docker-compose file can refer to the previous section. Here is the command to start TDengine with docker swarm:

$ VERSION=3.0.0.0 docker stack deploy -c docker-compose.yml taos
Creating network taos_inter
Creating network taos_api
Creating service taos_arbitrator
Creating service taos_td-1
Creating service taos_td-2
Creating service taos_adapter
Creating service taos_nginx

Checking status:

$ docker stack ps taos
ID                  NAME                IMAGE                     NODE                DESIRED STATE       CURRENT STATE                ERROR               PORTS
79ni8temw59n        taos_nginx.1        nginx:latest              TM1701     Running             Running about a minute ago
3e94u72msiyg        taos_adapter.1      tdengine/tdengine:3.0.0.0   TM1702     Running             Running 56 seconds ago
100amjkwzsc6        taos_td-2.1         tdengine/tdengine:3.0.0.0   TM1703     Running             Running about a minute ago
pkjehr2vvaaa        taos_td-1.1         tdengine/tdengine:3.0.0.0   TM1704     Running             Running 2 minutes ago
tpzvgpsr1qkt        taos_arbitrator.1   tdengine/tdengine:3.0.0.0   TM1705     Running             Running 2 minutes ago
rvss3g5yg6fa        taos_adapter.2      tdengine/tdengine:3.0.0.0   TM1706     Running             Running 56 seconds ago
i2augxamfllf        taos_adapter.3      tdengine/tdengine:3.0.0.0   TM1707     Running             Running 56 seconds ago
lmjyhzccpvpg        taos_adapter.4      tdengine/tdengine:3.0.0.0   TM1708     Running             Running 56 seconds ago
$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE                     PORTS
561t4lu6nfw6        taos_adapter        replicated          4/4                 tdengine/tdengine:3.0.0.0
3hk5ct3q90sm        taos_arbitrator     replicated          1/1                 tdengine/tdengine:3.0.0.0
d8qr52envqzu        taos_nginx          replicated          1/1                 nginx:latest              *:6041->6041/tcp, *:6044->6044/udp
2isssfvjk747        taos_td-1           replicated          1/1                 tdengine/tdengine:3.0.0.0
9pzw7u02ichv        taos_td-2           replicated          1/1                 tdengine/tdengine:3.0.0.0

From the above output, you can see two dnodes, two taosAdapters, and one Nginx reverse proxy service.

Next, we can reduce the number of taosAdapter services.

$ docker service scale taos_adapter=1
taos_adapter scaled to 1
overall progress: 1 out of 1 tasks
1/1: running   [==================================================>]
verify: Service converged

$ docker service ls -f name=taos_adapter
ID                  NAME                MODE                REPLICAS            IMAGE                     PORTS
561t4lu6nfw6        taos_adapter        replicated          1/1                 tdengine/tdengine:3.0.0.0